DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Borderless JButton

05.03.2005
| 10071 views |
  • submit to reddit
        To create a borderless JButton in swing use the following:

JButton taskButton = new JButton(action);
taskButton.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
taskButton.setHorizontalAlignment(JButton.LEADING); // optional
taskButton.setBorderPainted(false);
taskButton.setContentAreaFilled(false);

This is useful for "hyperlink" style buttons or "task buttons".