How to get JComboBox's MetalComboBoxButton object?
Hi,
I am using an non-editable JComboBox which has a MetalComboBoxButton component combined with it. I need to get the object of the MetalComboBoxButton from the JComboBox object. I tried everything I could think of but I still couldn't find it. There is no "get..." type of method to use to get it...
Could anyone please help me on this one?
Thank you very much.
Lifeng
Re: How to get JComboBox's MetalComboBoxButton object?
Yes Lifeng , As you said , there is no "get..." method to get Arrow button ..
You have to try something like this :
import javax.swing.*;
import javax.swing.plaf.basic.*;
public class ComboTest extends JFrame{
ComboEx combo = new ComboEx();
public ComboTest(){
this.getContentPane().add( combo );
}
public static void main( String[] str ){
ComboTest test = new ComboTest();
test.setVisible( true );
System.out.println( test.combo.getArrowButton());
}
// You have to do something like this ...
public static class ComboEx extends JComboBox{
ComboUI ui;
public void updateUI(){
super.updateUI();
ui = new ComboUI();
setUI( ui );
}
class ComboUI extends BasicComboBoxUI{
public JButton getArrowButton(){
// "arrowButton" is a protected variable in BasicComboBoxUI
return arrowButton;
}
}
public JButton getArrowButton(){
return ui.getArrowButton();
}
}
}