I'm using nimbus as L&F, but I really like to have a rounded shape combobox dropdown like seaglass L&F. See following images.
Nimbus
Seaglass
How can I achieve that effect? Is overriding paint helpful here? What would a method be?
Java JComboBox. The object of Choice class is used to show popup menu of choices. Choice selected by user is shown on the top of a menu. It inherits JComponent class. Let's see the declaration for javax.swing.JComboBox class.
Java Swing | JComboBox with examples. JComboBox is a part of Java Swing package. JComboBox inherits JComponent class . JComboBox shows a popup menu that shows a list and the user can select a option from that specified list . JComboBox can be editable or read- only depending on the choice of the programmer .
Sets the lightWeightPopupEnabled property, which provides a hint as to whether or not a lightweight Component should be used to contain the JComboBox, versus a heavyweight Component such as a Panel or a Window. Sets the maximum number of rows the JComboBox displays.
setEditable (boolean b) : the boolean b determines whether the combo box is editable or not .If true is passed then the combo box is editable or vice versa. setSelectedIndex (int i): selects the element of JComboBox at index i. showPopup () :causes the combo box to display its popup window.
Nimbus can be customized by updating UIManager properties. Example:
UIManager.put("nimbusBase", new Color(...));
UIManager.put("nimbusBlueGrey", new Color(...));
UIManager.put("control", new Color(...));
Painters can be updated as well. For example, custom slider:
The actual approach:
sliderDefaults.put("Slider.thumbWidth", 20);
sliderDefaults.put("Slider.thumbHeight", 20);
sliderDefaults.put("Slider:SliderThumb.backgroundPainter", new Painter() {
public void paint(Graphics2D g, JComponent c, int w, int h) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setStroke(new BasicStroke(2f));
g.setColor(Color.RED);
g.fillOval(1, 1, w-3, h-3);
g.setColor(Color.WHITE);
g.drawOval(1, 1, w-3, h-3);
}
});
Resources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With