Do you know any way to remove the border from a JComboBox in Java? I try the following code
public class ComboFrame extends JFrame {
public ComboFrame()
If you want to use the windows L&F, you can do cmd.setUI(new WindowsComboBoxUI());
If you, however, want to be able to use any L&F, you might be better off using the solution proposed by Jeach.
I did a bit of research and found this bug
I tried it for myself and it does seem to affect the border. You might want to try one or both of the following code blocks for yourself.
for (int i = 0; i < combo.getComponentCount(); i++)
{
if (combo.getComponent(i) instanceof JComponent) {
((JComponent) combo.getComponent(i)).setBorder(new EmptyBorder(0, 0,0,0));
}
if (combo.getComponent(i) instanceof AbstractButton) {
((AbstractButton) combo.getComponent(i)).setBorderPainted(false);
}
}
It is important to note that at the bottom of the bug entry, you can read the following:
The JButton maintains it's own border so JComponent paintBorder() and paintComponent() has no awareness of the JComboBox border.
Good luck,
Jeach!