CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2000
    Posts
    11

    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




  2. #2
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    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();
    }
    }
    }





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured