Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rounded popup for JCombobox

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

Enter image description here

Seaglass

Enter image description here

How can I achieve that effect? Is overriding paint helpful here? What would a method be?

like image 420
chAmi Avatar asked Nov 08 '12 19:11

chAmi


People also ask

How to show popup menu of choices in jcombobox?

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.

What is jcombobox in Java Swing?

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 .

What is the use of lightweightpopupenabled in jcombobox?

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.

How do I make a combo box editable in Java?

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.


1 Answers

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:

enter image description here

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:

  • See complete example here: Skinning a slider with nimbus
  • Nimbus defaults are listed here: Nimbus Defaults
like image 147
Renat Gilmanov Avatar answered Oct 14 '22 11:10

Renat Gilmanov