Extending JComboBox  behavior and changing look and feel

In order to change JComboBox behavior, usually we will extend the MetalComboBoxUI or WindowsComboBoxUI (for example: for controlling the popup width)
The problem arise when we want to be able to change the pluggable look and feel: all components got the new look and feel except for the comboboxes.
A dirty solution can be extending our ComboBoxUI from the new look and feel library but in the case of jgoodies it is even impossible because PlasticComboBoxUI is final
Any ideas?

In order to change JComboBox behavior, usually we will extend the MetalComboBoxUI or WindowsComboBoxUI (for example: for controlling the popup width).
The problem arise when we want to be able to change the pluggable look and feel: all components got the
new look and feel except for the comboboxes. A dirty solution can be extending our ComboBoxUI from
the new look and feel library but in the case of jgoodies it is even impossible because PlasticComboBoxUI is final
My best suggestion: request the L&F provider to make his combo box homogeneous with the other components.

Similar Messages

  • Change look n feel for java???????

    hi frens. can anyone tell me how i can change the look n feel for java. i mean i want to change the default window, buttons, color... say i want to have my the look n feel of my output like classic windows type. pls suggest me. thanks in advance....

    {color:#0000ff}http://java.sun.com/docs/books/tutorial/uiswing/lookandfeel/plaf.html{color}
    db

  • JComboBox Lost Listener on Look and Feel change

    When the user change the Look And Feel on the Fly , any Listener that is done using
    myComboBox.getEditor().getEditorComponent().addXXXListener
    is lost
    I'm using Windows XP Service Pack 2, java 6 build 105
    Does someone have any inputs why this happen or how this can be "fixed" or maybe prevent. Do I'm doing something wrong?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.util.*;
    import java.text.SimpleDateFormat;
    /* ComboBoxDemo2.java requires no other files. */
    public class ComboBoxDemo2 extends JPanel
                               implements ActionListener {
        static JFrame frame;
        JLabel result;
        String currentPattern;
        public ComboBoxDemo2() {
            setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
            String[] patternExamples = {
                     "dd MMMMM yyyy",
                     "dd.MM.yy",
                     "MM/dd/yy",
                     "yyyy.MM.dd G 'at' hh:mm:ss z",
                     "EEE, MMM d, ''yy",
                     "h:mm a",
                     "H:mm:ss:SSS",
                     "K:mm a,z",
                     "yyyy.MMMMM.dd GGG hh:mm aaa"
            currentPattern = patternExamples[0];
            //Set up the UI for selecting a pattern.
            JLabel patternLabel1 = new JLabel("Enter the pattern string or");
            JLabel patternLabel2 = new JLabel("select one from the list:");
            JComboBox patternList = new JComboBox(patternExamples);
            patternList.setEditable(true);
            patternList.addActionListener(this);
    //-------------------------------- XXX------------------------------------------
    //      This KeyListener it is lost when the user change the theme on the fly       
            patternList.getEditor().getEditorComponent().addKeyListener(new KeyAdapter()
            public void keyPressed(KeyEvent e)
             System.out.println(" Key pressed is "+e.getKeyCode());     
            //Create the UI for displaying result.
            JLabel resultLabel = new JLabel("Current Date/Time",
                                            JLabel.LEADING); //== LEFT
            result = new JLabel(" ");
            result.setForeground(Color.black);
            result.setBorder(BorderFactory.createCompoundBorder(
                 BorderFactory.createLineBorder(Color.black),
                 BorderFactory.createEmptyBorder(5,5,5,5)
            //Lay out everything.
            JPanel patternPanel = new JPanel();
            patternPanel.setLayout(new BoxLayout(patternPanel,
                                   BoxLayout.PAGE_AXIS));
            patternPanel.add(patternLabel1);
            patternPanel.add(patternLabel2);
            patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
            patternPanel.add(patternList);
            JPanel resultPanel = new JPanel(new GridLayout(0, 1));
            resultPanel.add(resultLabel);
            resultPanel.add(result);
            patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
            resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
            add(patternPanel);
            add(Box.createRigidArea(new Dimension(0, 10)));
            add(resultPanel);
            setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
            reformat();
        } //constructor
        public void actionPerformed(ActionEvent e) {
             System.out.println("Action Event");                
            JComboBox cb = (JComboBox)e.getSource();
            String newSelection = (String)cb.getSelectedItem();
            currentPattern = newSelection;
            reformat();
        /** Formats and displays today's date. */
        public void reformat() {
             try {
            Date today = new Date();
            SimpleDateFormat formatter =
               new SimpleDateFormat(currentPattern);
                String dateString = formatter.format(today);
                result.setForeground(Color.black);
                result.setText(dateString);
            }catch (IllegalArgumentException iae) {     
            System.out.println("Ilegal argument Exception");   
            catch (Exception e) {
            System.out.println("Argument Exception");                
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
        private static void createAndShowGUI() {
            //Create and set up the window.
            final JFrame frame = new JFrame("ComboBoxDemo2");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Create and set up the content pane.
            JComponent newContentPane = new ComboBoxDemo2();
            newContentPane.setOpaque(true); //content panes must be opaque
            frame.setLayout(new BorderLayout());      
            //frame.setContentPane(newContentPane,BorderLayout.CENTER);
            JMenuBar menuBar = new JMenuBar();
            JMenu theme = new JMenu("Theme");
            ButtonGroup bttnGroup = new ButtonGroup();
            JCheckBoxMenuItem metal = new JCheckBoxMenuItem("Metal");
            bttnGroup.add(metal);
            metal.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent e){
              try{
              UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
              SwingUtilities.updateComponentTreeUI(frame);
              }catch(Exception a){a.printStackTrace();}
              theme.add(metal);
            JCheckBoxMenuItem system = new JCheckBoxMenuItem("System");
            bttnGroup.add(system);
            system.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent e){
              try{
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              SwingUtilities.updateComponentTreeUI(frame);
              }catch(Exception a){a.printStackTrace();}
            theme.add(system);
            menuBar.add(theme);     
            frame.setJMenuBar(menuBar);
            JToolBar jtb = new JToolBar();
            jtb.add(newContentPane);
            frame.add(jtb, BorderLayout.PAGE_START);
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }

    Thanks to both Rodney_McKay and jasper for their replys and ideas
    This code is working fine
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.util.*;
    import java.text.SimpleDateFormat;
    /* ComboBoxDemo2.java requires no other files. */
    public class ComboBoxDemo2 extends JPanel
                               implements ActionListener {
        static JFrame frame;
        JLabel result;
        String currentPattern;
        private JComboBox patternList = new JComboBox();
        public ComboBoxDemo2() {
            setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
            String[] patternExamples = {
                     "dd MMMMM yyyy",
                     "dd.MM.yy",
                     "MM/dd/yy",
                     "yyyy.MM.dd G 'at' hh:mm:ss z",
                     "EEE, MMM d, ''yy",
                     "h:mm a",
                     "H:mm:ss:SSS",
                     "K:mm a,z",
                     "yyyy.MMMMM.dd GGG hh:mm aaa"
            currentPattern = patternExamples[0];
            //Set up the UI for selecting a pattern.
            JLabel patternLabel1 = new JLabel("Enter the pattern string or");
            JLabel patternLabel2 = new JLabel("select one from the list:");
            patternList = new JComboBox(patternExamples){
            public void updateUI(){
            System.out.println("UPDATE UI");
            super.updateUI();     
            changeUIAddEditorListener();
            changeUIAddEditorListener();
            patternList.setEditable(true);
            patternList.addActionListener(this);
            //Create the UI for displaying result.
            JLabel resultLabel = new JLabel("Current Date/Time",
                                            JLabel.LEADING); //== LEFT
            result = new JLabel(" ");
            result.setForeground(Color.black);
            result.setBorder(BorderFactory.createCompoundBorder(
                 BorderFactory.createLineBorder(Color.black),
                 BorderFactory.createEmptyBorder(5,5,5,5)
            //Lay out everything.
            JPanel patternPanel = new JPanel();
            patternPanel.setLayout(new BoxLayout(patternPanel,
                                   BoxLayout.PAGE_AXIS));
            patternPanel.add(patternLabel1);
            patternPanel.add(patternLabel2);
            patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
            patternPanel.add(patternList);
            JPanel resultPanel = new JPanel(new GridLayout(0, 1));
            resultPanel.add(resultLabel);
            resultPanel.add(result);
            patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
            resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
            add(patternPanel);
            add(Box.createRigidArea(new Dimension(0, 10)));
            add(resultPanel);
            setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
            reformat();
        } //constructor
        public void actionPerformed(ActionEvent e) {
             System.out.println("Action Event");                
            JComboBox cb = (JComboBox)e.getSource();
            String newSelection = (String)cb.getSelectedItem();
            currentPattern = newSelection;
            reformat();
        /** Formats and displays today's date. */
        public void reformat() {
             try {
            Date today = new Date();
            SimpleDateFormat formatter =
               new SimpleDateFormat(currentPattern);
                String dateString = formatter.format(today);
                result.setForeground(Color.black);
                result.setText(dateString);
            }catch (IllegalArgumentException iae) {     
            System.out.println("Ilegal argument Exception");   
            catch (Exception e) {
            System.out.println("Argument Exception");                
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
        private static void createAndShowGUI() {
            //Create and set up the window.
            final JFrame frame = new JFrame("ComboBoxDemo2");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Create and set up the content pane.
            JComponent newContentPane = new ComboBoxDemo2();
            newContentPane.setOpaque(true); //content panes must be opaque
            frame.setLayout(new BorderLayout());      
            //frame.setContentPane(newContentPane,BorderLayout.CENTER);
            JMenuBar menuBar = new JMenuBar();
            JMenu theme = new JMenu("Theme");
            ButtonGroup bttnGroup = new ButtonGroup();
            JCheckBoxMenuItem metal = new JCheckBoxMenuItem("Metal");
            bttnGroup.add(metal);
            metal.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent e){
              try{
              UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
              SwingUtilities.updateComponentTreeUI(frame);
              }catch(Exception a){a.printStackTrace();}
              theme.add(metal);
            JCheckBoxMenuItem system = new JCheckBoxMenuItem("System");
            bttnGroup.add(system);
            system.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent e){
              try{
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              SwingUtilities.updateComponentTreeUI(frame);
              }catch(Exception a){a.printStackTrace();}
            theme.add(system);
            menuBar.add(theme);     
            frame.setJMenuBar(menuBar);
            JToolBar jtb = new JToolBar();
            jtb.add(newContentPane);
            frame.add(jtb, BorderLayout.PAGE_START);
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
       public void changeUIAddEditorListener() {
       patternList.getEditor().getEditorComponent().addKeyListener(new KeyAdapter()
       public void keyPressed(KeyEvent e)
       System.out.println(" Key pressed is "+e.getKeyCode());     
    }

  • Function to change Boarder Look and feel of Jframe - Not working

    Hi all,
    In the given SSCE, the functionpublic void changeButtonColor(Component[] comps) to change the border look and feel of JFrame is not working.Please help.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Insets;
    import java.util.Vector;
    import javax.swing.AbstractButton;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JViewport;
    import javax.swing.SwingConstants;
    import javax.swing.UIManager;
    public class ScrollableWrapTest {
        public static void main(String[] args) {
            try {
                final JPanel mainPanel = new JPanel(new WrapScollableLayout(FlowLayout.LEFT, 10, 10));
                mainPanel.setBackground(Color.WHITE);
                JScrollPane pane = new JScrollPane(mainPanel);
                pane.setPreferredSize(new Dimension(320, 200));
                Vector v = new Vector();
                v.add("first");
                JButton button = null;
                for(int i =0;i<v.size();i++){
                        JPanel panel = new JPanel(new BorderLayout());
                        panel.setBackground(Color.WHITE);
                        int num = mainPanel.getComponentCount()+1;
                        button = new JButton("button" + num);
                        button.setPreferredSize(new Dimension(90, 25));
                        JLabel label = new JLabel((String)v.elementAt(i));
                        label.setHorizontalAlignment(SwingConstants.CENTER);
                        panel.add(button, BorderLayout.NORTH);
                        panel.add(label, BorderLayout.SOUTH);
                        mainPanel.add(panel);
                        mainPanel.revalidate();
                ScrollableWrapTest st = new ScrollableWrapTest();
                st.buildGUI(pane);
            } catch (Exception e) {e.printStackTrace();}
        public void buildGUI(JScrollPane scrollPane)
             JFrame frame = new JFrame("Scrollable Wrap Test");
             JFrame.setDefaultLookAndFeelDecorated(true);
            UIManager.put("activeCaption", new javax.swing.plaf.ColorUIResource(Color.LIGHT_GRAY));
            changeButtonColor(frame.getComponents());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(scrollPane, BorderLayout.CENTER);
            frame.setLocationRelativeTo(null);
            frame.pack();
            frame.setVisible(true);
        public void changeButtonColor(Component[] comps)
          for(int x = 0, y = comps.length; x < y; x++)
            if(comps[x] instanceof AbstractButton)
              ((AbstractButton)comps[x]).setBackground(Color.LIGHT_GRAY);
              ((AbstractButton)comps[x]).setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
            else if (comps[x] instanceof Container)
              changeButtonColor(((Container)comps[x]).getComponents());
        private static class WrapScollableLayout extends FlowLayout {
            public WrapScollableLayout(int align, int hgap, int vgap) {
                super(align, hgap, vgap);
            public Dimension preferredLayoutSize(Container target) {
                synchronized (target.getTreeLock()) {
                    Dimension dim = super.preferredLayoutSize(target);
                    layoutContainer(target);
                    int nmembers = target.getComponentCount();
                    for (int i = 0 ; i < nmembers ; i++) {
                        Component m = target.getComponent(i);
                        if (m.isVisible()) {
                            Dimension d = m.getPreferredSize();
                            dim.height = Math.max(dim.height, d.height + m.getY());
                    if (target.getParent() instanceof JViewport)
                        dim.width = ((JViewport) target.getParent()).getExtentSize().width;
                    Insets insets = target.getInsets();
                    dim.height += insets.top + insets.bottom + getVgap();
                    return dim;
    }Please help.
    Rony

    You are calling changeButtonColor(frame.getComponents()) before you add the JScrollPane to the content pane.
    But why not just move this to the button creation loop?
    button = new JButton("button" + num);
    button.setBackground(Color.LIGHT_GRAY);
    button.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));

  • Help on Look-and-Feel of JComboBox

    Can anyone guide me on how to change the look-and-feel and style of a JComboBox? Is it possible? If yes, how?

    I was wondering about that myself... I want to change the look of a combobox, or any other component. I think I should do it with the following code
    public static void setLookAndFeel(String�className)
    but I don't know what className to use. If I am not mistaken it should be the name of the class that implements the Look and Feel, please help!

  • How to change the default look and feel

    Hi.
    Does anyone knows how to change the default Caspian look and feel to, for example, Nimbus ?
    Or the skin feature turns look and feel setting, as We know in java, unnecessary in javafx ?
    I´m using javafx 1.2.
    Cheers

    Canspian is not a look&feel, it's a skin.
    Look&feel only change the SwingComponent,
    regards.

  • How can we remove the space after changing look and feel to generic

    Hi
    I want to remove the space which left blank after changing look and feel to generic in formsweb.cfg file.
    Can anybody help me to remove this blank space.

    Hi,
    can you be more specific on teh space you mean?
    Frank

  • Change of Layout/Look and Feel in BI 7 Reports.

    Hi,
    This is Prem from NetWeaver Portals.
    Currently we have a couple of BI 7.0 reports integrated into portal.
    We have also used Portal Themes to alter the Look and Feel of the BI reports with respect to Heading colors, alternate row colors etc. But the scope of changing the Look and feel of BI reports from the Portal theme is very limited.
    Is there a way to modify it further from BI's CSS?
    Where is this functionality provided in SAP BI 7.0?
    We are also interested in changing the Layout of the reports in BI. i.e. unlike the standard BI format of reports as generated from the Web Application designer, we would like to change the layout as well.
    How is this layout change carried out? Web Templates?
    Kindly spell out a solution for me as I'm not aware of BI
    Thanks and Regards,
    Prem

    Could yo please explain little detial. how do you changed the look and feel of reports through the portal themes. We are trying to change the colors of the execptions and text box and some more.  we have created a custom theme  in which we changed the  complex formatted table  crictal, bad, good colors. when we assigned this theme through personalization to the user, custom theme colors are not seen in the BW report. 
    Please let us know
    thanks and regards
    venkata bandi

  • How Can You Change the Look and Feel of Charts in OBIEE 11g

    How Can You Change the Look and Feel of Charts in OBIEE 11g?
    Edited by: user11973122 on Jul 18, 2012 12:13 AM

    Check these files
    OFM_HOME\Oracle_BI1\bifoundation\web\msgdb\s_blafp\viewui\chart\dvt-graph-skin.xml
    OFM_HOME\Oracle_BI1\bifoundation\web\msgdb\views\dvtchart\obips.dvtchart.xml
    OFM_HOME\Oracle_BI1\bifoundation\web\display\chartfontmapping.xml
    Pls mark correct or helpful if helps

  • Can we change the look and feel of the screen layout

    Dear All,
    I am new to ABAP WebDynpro, and would like to know the following with respect to ABAP WebDynpro :
    1. To what extent can we change the look and feel of the screen layout ?
    2. Is it possible to change the background color of the layout?
    3. Is it possible to change the color of, Buttons etc ?
    Any information / document/ link to explain this would be very helpful ..
    Thanks in advance,
    Aditi

    Hi,
    Psl check out these links.
    check out these webdynpro standard components in SE80 tcode -
    WDR_TEST_UI_ELEMENTS
    check out this link on webdynpro for ABAP-
    http://help.sap.com/saphelp_nw70/helpdata/EN/03/0048413e466e24e10000000a155106/frameset.htm-WD for ABAP
    http://help.sap.com/saphelp_nw70/helpdata/EN/46/9319f88f8115ebe10000000a114a6b/frameset.htm -UI elements
    http://help.sap.com/saphelp_nw70/helpdata/EN/46/9319f88f8115ebe10000000a114a6b/frameset.htm-Button Properties
    http://help.sap.com/saphelp_nw70/helpdata/EN/46/9319f88f8115ebe10000000a114a6b/frameset.htm- For different Layouts
    Regards
    Lekha

  • How to change the look and feel for Heading of quick launch menu in project server 2010

    Hi
    can someone tell me how to change the look and feel of Header names in quick launch.
    I want the header to be displayed in Bold with Underline to it.
    could this be possible for just header in quick launch in project server 2010. 

    Hi Rohan
    It does not work this way. You have to use a content editor webpart.
    See references below that might help you starting with this customisation:
    Http://go4answers.webhost4life.com/Example/sharepoint-2010-quick-launch-look-feel-78379.aspx
    Http://m.sharepointpromag.com/sharepoint/four-ways-add-or-remove-quick-launch-menu-control
    Hope this helps.
    Guillaume Rouyre - MBA, MCP, MCTS

  • UIX: change image in corporateBranding dependent on choosen Look And Feel

    Is it possible to change a image used in the corporateBranding dependent on choosen Look And Feel?

    If your corporate branding is an image, you can to bind the "source" attribute and return the appropriate image depending on the laf. You can get the laf off the renderingContext. The data binding chapter is here:
    http://helponline.oracle.com/jdeveloper/help/state/content/vtTopicId./navSetId.jdeveloper/vtTopicFile.jdeveloper%7Cuixhelp%7Cuixdevguide%7Cdatabinding%7Ehtml/navId.4/

  • Change XP Look and Feel Rollover Highlight Color

    Is it possible to change the orange rollover highlight color that is used in the Windows XP Look and Feel? If so, how? I want to change it in once place and see the results on every component in my application.

    By the way, I'm using 1.5

  • Change in look and feel

    Hi
    After the Server has restarted the look and feel of the portal has been changed.
    could any one tell me what could be the problem for this change?
    regards
    ambicasony

    Ok,
    is it a bad looking look and feel, i mean do you think this look and feel contains error or is kind of bugged ?
    what i am trying to know, is if this new look and feel cames from a portal desktop change or if it is really a bug.
    Message was edited by:
            Fabien REVOL

  • Losing Title Bar when changing Look and Feel on the fly

    Hello,
    I have an option in my Swing app for the user to change the Look & Feel on the fly by selecting from a radio button list. The look and feel is changed when the user make the selection, however the Windows Title Bar disappears. Any ideas what I'm missing?
    private void setLook(String mode)
    String lookAndFeelClassName = null;
    UIManager.LookAndFeelInfo looks[] = UIManager.getInstalledLookAndFeels();
    for (int i = 0; i < looks.length; i++)
    if (mode.equalsIgnoreCase(looks.getName()))
    lookAndFeelClassName = looks[i].getClassName();
    break;
    try
    m_view.dispose();
    UIManager.setLookAndFeel(lookAndFeelClassName);
    SwingUtilities.updateComponentTreeUI(m_view);
    m_view.setVisible(true);
    catch (Exception e)
    JOptionPane.showMessageDialog(m_view, "Can't change look and feel:" + lookAndFeelClassName, "Invalid PLAF", JOptionPane.ERROR_MESSAGE);

    You are disposing the view. My guess is that this is your problem. Try creating a new one instead of just showing the old disposed one

Maybe you are looking for