I'm using a custom BasicComboBoxRenderer for a JComboBox and I've changed the appearance of the items of the drop-down list. However these changes also apply to the single top item that shows in the combobox (don't know how to call it).
I want the top item to be independent of the other items in the list, if possible. I would also like to get rid of the top item's blue color when it is focused (setFocusable(false) is not what I want).
I've tried to use the "renderer index" (-1) to affect the top item but it doesn't seem to help.
Any ideas?
P.S Unfortunately I couldn't add images to be more clear (no reputation).
EDIT: When I say that I want the top item to be independent from all the other items of the drop-down list I mean to always look different from the rest of them. For example in my custom BasicComboBoxRenderer I've set the selected item to have a different background, but this background also applies to the top item (since the selected item becomes the top item of the combobox).
EDIT 2: top item = I meant the combobox display area, so I want to affect the item that is shown at the display area and not the first item in the drop-down list. I managed to do this by using setBackground on the combobox itself AND setFocusable(false) (which is not very helpful because I want to keep the focus mechanism). But the problem is (except the focus issue) that if for example I set a border on each item in the list through a custom BasicComboBoxRenderer or ListCellRenderer class, this same border appears on the item that is shown in the display area. So there are 2 questions here:
--Is there any way to differentiate the layout of the items in the drop-down list and the single item in the display area?
--Is there any way to disable the focus color of the combobox without disabling the focus mechanism, just like when we use setFocusPainted(false) on buttons? (I've also tried to add a custom FocusListener on the combobox but any change made of the background through focusGained() affects only the button and not the item shown in the display area).
Sorry for the confusion and the multiple edits...
have look at Combo Box Prompt by #camickr,
defined prompt can't returns any value from JComboBox.getSelectedXxx
EDIT
BasicComboBoxRenderer or ListCellRenderer can do that this way
import java.awt.*;
import javax.swing.*;
public class TestHighLightRow {
public void makeUI() {
Object[] data = {"One", "Two", "Three"};
JComboBox comboBox = new JComboBox(data);
comboBox.setPreferredSize(comboBox.getPreferredSize());
comboBox.setRenderer(new HighLightRowRenderer(comboBox.getRenderer()));
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(comboBox);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
new TestHighLightRow().makeUI();
}
});
}
public class HighLightRowRenderer implements ListCellRenderer {
private final ListCellRenderer delegate;
private int height = -1;
public HighLightRowRenderer(ListCellRenderer delegate) {
this.delegate = delegate;
}
#Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component component = delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
Dimension size = component.getPreferredSize();
if (index == 0) {
component.setBackground(Color.red);
if (component instanceof JLabel) {
((JLabel) component).setHorizontalTextPosition(JLabel.CENTER);
}
}
return component;
}
}
}
EDIT2
JComboBox has two states
editable
non_editable
basically all values could be accesible from UIManager, shortcuts
import java.awt.*;
import java.util.Vector;
import javax.swing.*;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.metal.MetalComboBoxButton;
public class MyComboBox {
private Vector<String> listSomeString = new Vector<String>();
private JComboBox someComboBox = new JComboBox(listSomeString);
private JComboBox editableComboBox = new JComboBox(listSomeString);
private JComboBox non_EditableComboBox = new JComboBox(listSomeString);
private JFrame frame;
public MyComboBox() {
listSomeString.add("-");
listSomeString.add("Snowboarding");
listSomeString.add("Rowing");
listSomeString.add("Knitting");
listSomeString.add("Speed reading");
//
someComboBox.setPrototypeDisplayValue("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
someComboBox.setFont(new Font("Serif", Font.BOLD, 16));
someComboBox.setEditable(true);
someComboBox.getEditor().getEditorComponent().setBackground(Color.YELLOW);
((JTextField) someComboBox.getEditor().getEditorComponent()).setBackground(Color.YELLOW);
//
editableComboBox.setPrototypeDisplayValue("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
editableComboBox.setFont(new Font("Serif", Font.BOLD, 16));
editableComboBox.setEditable(true);
JTextField text = ((JTextField) editableComboBox.getEditor().getEditorComponent());
text.setBackground(Color.YELLOW);
JComboBox coloredArrowsCombo = editableComboBox;
Component[] comp = coloredArrowsCombo.getComponents();
for (int i = 0; i < comp.length; i++) {
if (comp[i] instanceof MetalComboBoxButton) {
MetalComboBoxButton coloredArrowsButton = (MetalComboBoxButton) comp[i];
coloredArrowsButton.setBackground(null);
break;
}
}
//
non_EditableComboBox.setPrototypeDisplayValue("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
non_EditableComboBox.setFont(new Font("Serif", Font.BOLD, 16));
//
frame = new JFrame();
frame.setLayout(new GridLayout(0, 1, 10, 10));
frame.add(someComboBox);
frame.add(editableComboBox);
frame.add(non_EditableComboBox);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(100, 100);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
UIManager.put("ComboBox.background", new ColorUIResource(Color.yellow));
UIManager.put("JTextField.background", new ColorUIResource(Color.yellow));
UIManager.put("ComboBox.selectionBackground", new ColorUIResource(Color.magenta));
UIManager.put("ComboBox.selectionForeground", new ColorUIResource(Color.blue));
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
MyComboBox aCTF = new MyComboBox();
}
});
}
}
Related
Below is the minimum reproducible code. In MouseClicked method with mouseevent i got that Jpanel is clicked by using getelementat() method.
But which button on JPanel is clicked can not figure. Tried with convert point but making some mistake. Need to check which button on Jpanel is clicked. Need some help.
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class JListTest {
private JList list;
private DefaultListModel dataModel ;
private JTableTest tableTest;
private JPanel panel = new JPanel();
public JListTest() {
dataModel = new DefaultListModel();
list = new JList<>(dataModel);
list.addMouseListener(new MouseAdapter() {
#Override
public void mouseClicked(MouseEvent me) {
super.mouseClicked(me);
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
JList target = (JList) me.getSource();
int index = target.locationToIndex(me.getPoint());
JPanel item = (JPanel) target.getModel().getElementAt(index);
Point p=SwingUtilities.convertPoint(target,me.getPoint(),item);
item.getComponentAt(p);
}
});
}
});
list.setCellRenderer(new PanelRenderer());
}
public static void main(String []args){
JListTest test=new JListTest();
test.dataModel.addElement("Lable 1");
test.dataModel.addElement("Lable 2");
test.dataModel.addElement("Lable 3");
JButton button1 = new JButton("Button 1");
JButton button2 = new JButton("Button 2");
test.panel.add(button1);
test.panel.add(button2);
test.dataModel.addElement(test.panel);
test.showUi();
}
public void showUi(){
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Demo list");
frame.setAlwaysOnTop(true);
frame.setType(Window.Type.UTILITY);
frame.setResizable(true);
frame.getContentPane().setLayout(new BorderLayout());
JScrollPane scrollPane = new JScrollPane(list);
scrollPane.setPreferredSize(new Dimension(400, 250));
frame.getContentPane().add(scrollPane, BorderLayout.NORTH);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.setSize(500, 300);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
class PanelRenderer implements ListCellRenderer {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if(value instanceof String){
return new DefaultListCellRenderer().getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
}
return (Component) value;
}
}
}
Blockquote
item.getComponentAt(p);
What is the point of that statement? How can you tell if the code worked or not since you never assign the result of the method to a variable?
Turns out that because the panel is not really a component displayed on the frame you can't just do as I originally suggested.
If you add code like:
JPanel item = (JPanel) target.getModel().getElementAt(index);
System.out.println( item.getBounds() );
You get output like:
java.awt.Rectangle[x=-487,y=-36,width=0,height=0]
Which doesn't make any sense.
So, I changed the logic to assign the bounds to the panel as if it was displayed on the JList:
item.setBounds(target.getCellBounds(index, index));
Now, I get output like:
java.awt.Rectangle[x=0,y=54,width=487,height=36]
Which does make more sense. However, that still doesn't help because if you add:
Point p = SwingUtilities.convertPoint(target,me.getPoint(),item);
System.out.println( p );
You get something like:
java.awt.Point[x=834,y=166]
The conversion of the point does do what I expected.
So, I decided to convert the point manually:
int y = me.getY() - item.getBounds().y;
Point p = new Point(me.getX(), y);
Putting it all together you get something like:
JList target = (JList) me.getSource();
int index = target.locationToIndex(me.getPoint());
JPanel item = (JPanel) target.getModel().getElementAt(index);
item.setBounds(target.getCellBounds(index, index));
int y = me.getY() - item.getBounds().y;
Point p = new Point(me.getX(), y);
JButton button = (JButton)item.getComponentAt(p);
System.out.println(button.getText());
And you get the text of the button when you click on it.
Of course, you get Exceptions if you click anywhere else. I'll leave it up to you do handle the Exception logic.
Note, I see your latest question is about adding labels and a panel to a frame. It is a much better approach to use real components as you can add ActionListeners to your buttons.
I have used Romain Hippeau's answer. In order to set the default font of the application when it is first built.
public static void setUIFont(javax.swing.plaf.FontUIResource f) {
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource)
UIManager.put(key, f);
}
And then calling it:
setUIFont(new javax.swing.plaf.FontUIResource("Sans", Font.PLAIN, 24));
However when new text is written to the swing application: I.e
JTextArea textArea = new JTextArea();
onSomeEventHappening(){
textArea.setText("Hello world");
}
Hello world appears in the standard swing font whereas all my other elements remain at the font I want everything to stay in. Is there any way to make sure that all new text added to the application, doesn't have its font changed.
Above shows an example of this, the word "FOOTBALL" has be written into its combo box and therefore appears with Swing's normal font, whereas my button "Generate one link"appears in the font I've set.
Below shows a copy and paste example, if you click on the button, despite setting the font above, the label is still in Swings original style:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class test extends JFrame {
private static final int WIDTH = 1000;
private static final int HEIGHT = 700;
private JTextArea textArea = new JTextArea();
public static void setUIFont(javax.swing.plaf.FontUIResource f) {
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource)
UIManager.put(key, f);
}
}
public test(){
initialize();
}
final ActionListener buttonClick = new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
textArea.setText("new Text");
}
};
public void initialize(){
new JFrame();
setBounds(100, 100, 450, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new GridLayout(1,2));
setUIFont(new javax.swing.plaf.FontUIResource("Sans", Font.PLAIN, 24));
JButton button = new JButton("test");
button.addActionListener(buttonClick);
this.add(button);
this.add(textArea);
setVisible(true);
}
public static void main(String[] args){
test test1 = new test();
}
}
private JTextArea textArea = new JTextArea();
...
setUIFont(new javax.swing.plaf.FontUIResource("Sans", Font.PLAIN, 24));
...
JButton button = new JButton("test");
You have already created the JTextArea before you change the font.
The Swing component gets its UI properties at the time it is created.
So you need to create the JTextArea AFTER you set the font, the same as you do with the JButton.
Note: if you change the properties after the components have been created then you need to reset the properties.
SwingUtilities.updateComponentTreeUI(frame);
frame.pack();
Read the section from the Swing tutorial on How to Set the Look and Feel After Startup for more information.
I'm currently creating a soundboard application where the person is going to click one of the items in my JList and its going to set the name of the next available text field as what was just clicked then i'm going to add buttons later.
For example, if my first click is the 2nd item in the JList it will go into the first JTextfield and my second click will go into the second JTextfield.
The program will have around 100 items in the JList by the time the app is done.
Also there is a problem that when the top one and a different JList item is clicked the top one will display first. Not necessarily a problem if I can get the problem fully functional but it makes it feel a little wonky.
package com.leagueoflegends.soundboard;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
public class Soundboard implements ListSelectionListener {
static JList<Object> list;
String[] text = { "hello", "testing1", "testing2" };
Icon icon;
JLabel pictureLabel;
JPanel insidePanel;
JTextField inlineText;
JTextField field[] = new JTextField[6];
public Soundboard() {
JFrame f = new JFrame("soundboard!");
JPanel masterPanel = new JPanel(new BorderLayout());
//icon = new ImageIcon(getClass().getResource("Tray.png"));
//pictureLabel = new JLabel(icon);
list = new JList<Object>(text); // data has type Object[]
list.setSelectionModel(new DefaultListSelectionModel(){
public void setSelectionInterval(int index0, int index1){
if(super.isSelectedIndex(index0)){
super.removeSelectionInterval(index0,index1);
}else{
super.addSelectionInterval(index0,index1);
}
}
});
list.setLayoutOrientation(JList.VERTICAL_WRAP);
list.setVisibleRowCount(-1);
list.addListSelectionListener(this);
JScrollPane listScroller = new JScrollPane(list);
listScroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
listScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
listScroller.setPreferredSize(new Dimension(100, 60));
// listScroller.setSize(new Dimension(250, 60));
JPanel smallPanel = new JPanel(new GridLayout(2, 3));
// smallPanel.setBorder(BorderFactory.createLineBorder(Color.red));
for (int i = 0; i <= 5; i++) {
insidePanel = new JPanel(new BorderLayout());
insidePanel.setBorder(BorderFactory.createLineBorder(Color.black));
field[i] = new JTextField();
field[i].setEditable(false);
field[i].setHorizontalAlignment(JTextField.CENTER);
insidePanel.add(field[i], BorderLayout.PAGE_START);
smallPanel.add(insidePanel);
}
masterPanel.add(smallPanel);
masterPanel.add(pictureLabel, BorderLayout.PAGE_START);
masterPanel.add(listScroller, BorderLayout.WEST);
f.add(masterPanel);
f.pack();
f.setSize(1000, 800);
f.setMinimumSize(new Dimension(400, 350));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting() == false) {
for (int i = 0; i < text.length; i++) {
if (list.getSelectedIndex() == i) {
field[0].setText(text[i]);
}
}
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
new Soundboard();
}
});
}
If i understood your question correct than you have to provide a custom list model to your list. You can initialize your JList with this custom list model.
The entries of your list model hold a reference to
an appropriate textfield instance. So each time you select an entry of the list you
have access to your custom list item you can manipulate the text of the associated textfield.
The custom list model must implement the ListModel interface or extend AbstractListModel class.
There are many nice tutorials have a look here:
Swing/UsingaCustomDataModel.htm">http://www.java2s.com/Tutorial/Java/0240_Swing/UsingaCustomDataModel.htm
Hope it helps.
In my current swing project I have a JList displaying all active sockets, and each cell has a JButton to close that socket. But the JButton in the cell is not clickable: listener does not get fired.
I have modified the code to minimal as follows.
private class ConnectionListRenderer extends JButton implements ListCellRenderer {
public Component getListCellRendererComponent(JList jlist, Object o, int i, boolean bln, boolean bln1) {
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//do something (close the socket in my project)
}
});
return this;
}
}
jList.setCellRenderer(new ConnectionListRenderer());
The list looks fine, but the button on in is not clickable. Am I wrong or JList just does not support JButton in the getting fired?
Here's an example that seems to work, although you don't get the same visual effect of a normal button click. Perhaps someone with better painting skill than me could improve this to simulate the visual pressed button effect.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* A JList of JButtons.
*/
public class JButtonListDemo implements Runnable
{
private JList jlist;
public static void main(String args[])
{
SwingUtilities.invokeLater(new JButtonListDemo());
}
public void run()
{
Object[] items = new ButtonItem[] {
new ButtonItem("Apple"),
new ButtonItem("Banana"),
new ButtonItem("Carrot"),
new ButtonItem("Date"),
new ButtonItem("Eggplant"),
new ButtonItem("Fig"),
new ButtonItem("Guava"),
};
jlist = new JList(items);
jlist.setCellRenderer(new ButtonListRenderer());
jlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jlist.setVisibleRowCount(5);
jlist.addMouseListener(new MouseAdapter()
{
#Override
public void mouseClicked(MouseEvent event)
{
clickButtonAt(event.getPoint());
}
});
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new JScrollPane(jlist));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private void clickButtonAt(Point point)
{
int index = jlist.locationToIndex(point);
ButtonItem item = (ButtonItem) jlist.getModel().getElementAt(index);
item.getButton().doClick();
// jlist.repaint(jlist.getCellBounds(index, index));
}
public class ButtonItem
{
private JButton button;
public ButtonItem(String name)
{
this.button = new JButton(name);
button.addActionListener(new ActionListener()
{
#Override
public void actionPerformed(ActionEvent e)
{
System.out.println(button.getText() + " was clicked.");
}
});
}
public JButton getButton()
{
return button;
}
#Override
public String toString()
{
return button.getText();
}
}
class ButtonListRenderer extends JButton implements ListCellRenderer
{
public Component getListCellRendererComponent(JList comp, Object value, int index,
boolean isSelected, boolean hasFocus)
{
setEnabled(comp.isEnabled());
setFont(comp.getFont());
setText(value.toString());
if (isSelected)
{
setBackground(comp.getSelectionBackground());
setForeground(comp.getSelectionForeground());
}
else
{
setBackground(comp.getBackground());
setForeground(comp.getForeground());
}
return this;
}
}
}
Alternatively, you could always layout your JButtons vertically on a JPanel (using a new GridLayout(0,1) perhaps) and then put your JPanel in a JScrollPane, thus mocking a JList of JButtons.
Render's are not "real" components, they are "rubber stamps" painted onto the surface of the parent component. They have no "physical" presence.
A JList will have only one instance of the render and this is used to "stamp" each of the items from the list model onto the view.
Out of the box, JList is not editable.
Another solution would be to use two lists next to each other. The first one renders the actual list content, while the second renders buttons, you can add the two lists to a JPanel and layout them with BorderLayout (Borderlayout.CENTER and BorderLayout.EAST). Add this JPanel to the viewport of a JScrollPane.
In connections with these two post #iMohammad,
Increasing/Decreasing Font Size inside textArea using JButton and
Changing Font Style when Clicking on a JButton Java ..., I'm facing with really funny issue that came from JComboBoxby passing setPrototypeDisplayValue as an argument for JComboBox's size on the screen
please how can I resize JComboBox dynamically depends of Font, same as works correctly for another JComponents that I tried in my sscce
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ComboBoxFontChange extends JFrame {
private static final long serialVersionUID = 1L;
private JComboBox cbox = new JComboBox();
private JTextField tfield = new JTextField("Change");
private JLabel label = new JLabel("Cash");
private JButton button = new JButton("++ Font");
private JTextField text;
private JPanel panel = new JPanel();
public ComboBoxFontChange() {
super("Combo Box Font change");
text = (JTextField) cbox.getEditor().getEditorComponent();
cbox.addItem("Change");
cbox.addItem("Cash");
cbox.addItem("Font");
tfield.setColumns(5);
button.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
Font font = cbox.getFont();
font = font.deriveFont((float) (font.getSize2D() * 1.10));
cbox.setFont(font);
// EDIT
cbox.setPrototypeDisplayValue(cbox.getSelectedItem().toString());
tfield.setFont(font);
button.setFont(font);
label.setFont(font);
//panel.revalidate();
//panel.repaint();
pack();
}
});
//panel.setLayout(new GridLayout(2, 2, 10, 10));
panel.add(cbox);
panel.add(label);
panel.add(tfield);
panel.add(button);
setDefaultCloseOperation(EXIT_ON_CLOSE);
add(panel);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
ComboBoxFontChange frame = new ComboBoxFontChange();
frame.pack();
frame.setVisible(true);
}
});
}
}
I debugged your SSCCE, and the value passed to setPrototypeDisplayValue is the empty string. Changing the line to
cbox.setPrototypeDisplayValue(cbox.getSelectedItem());
Makes everything work as expected. Removing the call to setPrototypDisplayValue also makes the program behave as expected.
EDIT:
The other problem is that no event is fired for the prototype display value because you set it to the previous value as before, and an event is only fired if the value actually changes. Adding cbox.setPrototypeDisplayValue(""); before cbox.setPrototypeDisplayValue(cbox.getSelectedItem().toString()) makes everything behave as expected, even on JDK 1.6. I agree that given that the font is changed, the preferred size should be recomputed, but at least this change is a workaround.
I tried what JB Nizet said. But for me the comboBox size didnt change. How about you?
So i tried the following and the combobox size increased as i increased the font size.
cbox.setFont(font);
cbox.updateUI();
I also removed the line
cbox.setPrototypeDisplayValue(text.getText());
For reference, a GridLayout and eight clicks gave this result on Mac OS X:
panel.setLayout(new GridLayout(0, 1, 10, 10));
Combo: Popup:
As an aside, cbox.updateUI() restored the defaults prescribed by the Aqua UI delegate, com.apple.laf.AquaComboBoxUI.
Here is the code from the BasicComboBoxUI:
else if ( propertyName == "font" ) {
listBox.setFont( comboBox.getFont() );
if ( editor != null ) {
editor.setFont( comboBox.getFont() );
}
isMinimumSizeDirty = true;
comboBox.validate();
}
else if ( propertyName == JComponent.TOOL_TIP_TEXT_KEY ) {
updateToolTipTextForChildren();
}
else if ( propertyName == BasicComboBoxUI.IS_TABLE_CELL_EDITOR ) {
Boolean inTable = (Boolean)e.getNewValue();
isTableCellEditor = inTable.equals(Boolean.TRUE) ? true : false;
}
else if (propertyName == "prototypeDisplayValue") {
isMinimumSizeDirty = true;
isDisplaySizeDirty = true;
comboBox.revalidate();
}
For some reason a Font change only resets the "minimum size" not the "display size".