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() {
JPanel container = new JPanel();
JComboBox cmb = new JComboBox(new String[] { "one", "two" });
cmb.setBorder(BorderFactory.createEmptyBorder());
container.add(cmb);
getContentPane().add(container);
pack();
}
}
and
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
EventQueue.invokeLater(new Runnable() {
public void run() {
new ComboFrame().setVisible(true);
}
});
}
Don't ask why would someone want to remove the border from a combobx... I guess it does not make too much sense, but this is how it's wanted, and I got really curious if it can be done. I tried several tricks, but none of them worked.
The most effective was changing the UI with
cmb.setUI(new BasicComboBoxUI());
This makes the border go away, but alters the L&F, and I need to keep the Windows L&F if possible.
Thanks.