Over a million developers have joined DZone.

Borderless JButton

·
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".
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}