UIManager.look and feel buttons or javax.swing

Hey,
i want to use the ok, cancel etc. button that you get in a JFileChooser or a JOptionPane.
Can they be found in the UIManager or in the javax.swing?
i tried to extract them from the JFileChooser by:
JFileChooser chooser = new JFileChooser("/"); //Linux
JPanel mypanel = new JPanel();
mypanel.add(chooser.getComponentAt(2)); //the button panelthis works, but i don't know how to overwrite the actionlistener to make the buttons listen to my actionlistener.
thanks in advance
Grad_

It returns an int value according to what button was clicked
http://72.5.124.55/docs/books/tutorial/uiswing/components/filechooser.html
http://java.sun.com/developer/JDCTechTips/2004/tt0316.html

Similar Messages

  • Problem With ButtonUI in an Auxiliary Look and Feel

    This is my first post to one of these forums, so I hope everything works correctly.
    I have been trying to get an axiliary look and feel installed to do some minor tweaking to the default UI. In particular, I need it to work with Windows and/or Metal as the default UI. For the most part I let the installed default look and feel handle things with my code making some colors lighter, darker, etc. I also play with focus issues by adding FocusListeners to some components. I expect my code to work reasonably well no matter what the default look and feel is. It works well with Motif, Metal, and Windows, the only default look and feels I've tested with. What I'm going to post is a stripped down version of what I have been working on. This example makes gross changes to the JButton background and foreground colors in order to illustrate what I've encountered.
    I have three source code files. The first, Problem.java, creates a JFrame and adds five buttons to it. One button installs MyAuxLookAndFeel as an auxiliary look and feel using MyAuxButtonUI for the look and feel of JButtons. The next button removes that look and feel. The next button does nothing except print a line to System.out. The next button installs MyAuxLookAndFeel as an auxiliary look and feel using MyModButtonUI for the look and feel of JButtons. The last button removes that look and feel.
    The problem is, when I install the first auxiliary look and feel, buttons are no longer tabable. Also, they cannot be invoked by pressing the space button when they're in focus. When I remove the first auxiliary look and feel everything reverts to behaving normally. When I add the "Mod" version, button tabability is fine. The only difference is I've added the following code:
    if ( c.isFocusable() ) {
       c.setFocusable(true);
    }That strikes me as an odd piece of code to profoundly change the program behavior. Anyway, after adding and removing the "Mod" look and feel, the tababilty is forever fixed. That is, if I subsequently re-install the first look and feel, tababilty works just fine.
    The problem with using the space bar to select a focused button is more problematic. My class is not supposed to mess with the default look and feel which may or may not use the space bar to press the button with focus. When the commented code in MyModButtonUI is uncommented, things behave correctly. Even the statement
    button.getInputMap().remove( spaceKeyStroke );doesn't mess things up after the auxiliary look and feel is removed. So far I've tested this with JRE 1.4.2_06 under Windows 2000, JRE 1.4.2_10 under Windows XP, and JRE 1.5.0_06 under Windows XP and the behavior is the same.
    All of this leads me to two questions.
    1. Is my approach fundamentally flawed? I've extended TextUI and ScrollBarUI with no problems. This is the only problem I've encountered with ButtonUI. My real workaround for the space bar issue is better than the one I've supplied in the example, but it certainly is not guaranteed to work for any arbitrary default look and feel.
    2. Assuming I have no fundamental problems with my approach, it's possible I've found a real bug. I searched the bug database and couldn't find anything like this. Of course, this is the first time I've tried seasrching the database for a bug so my I'm doing it badly. Has this already been reported as a bug? Is there any reason I shouldn't report it?
    What follows is the source code for my example. It's in three files because the two ButtonUI classes must be public in order to work. Thanks for insight you can provide.
    Bill
    File Problem.java:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Problem extends JFrame {
       public boolean isAuxInstalled = false;
       public boolean isModInstalled = false;
       public LookAndFeel lookAndFeel = new MyAuxLookAndFeel();
       private static int ctr = 0;
       public static void main( String[] args ) {
          new Problem();
       public Problem() {
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setSize(250, 150);
          setTitle("Button Test");
          JButton install = new JButton("Install");
          JButton remove = new JButton("Remove");
          JButton doNothing = new JButton("Do Nothing");
          JButton installMod = new JButton("Install Mod");
          JButton removeMod = new JButton("Remove Mod");
          this.getContentPane().setLayout(new FlowLayout());
          this.getContentPane().add(install);
          this.getContentPane().add(remove);
          this.getContentPane().add(doNothing);
          this.getContentPane().add(installMod);
          this.getContentPane().add(removeMod);
          install.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( !isAuxInstalled ) {
                   isAuxInstalled = true;
                   UIManager.addAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          remove.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( isAuxInstalled ) {
                   isAuxInstalled = false;
                   UIManager.removeAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          doNothing.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                System.out.println( "Do nothing " + (++ctr) );
          installMod.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( !isModInstalled ) {
                   isModInstalled = true;
                   UIManager.addAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          removeMod.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( isModInstalled ) {
                   isModInstalled = false;
                   UIManager.removeAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          setVisible(true);
       class MyAuxLookAndFeel extends LookAndFeel {
          public String getName() {
             return "Button Test";
          public String getID() {
             return "Not well known";
          public String getDescription() {
             return "Button Test Look and Feel";
          public boolean isSupportedLookAndFeel() {
             return true;
          public boolean isNativeLookAndFeel() {
             return false;
          public UIDefaults getDefaults() {
             UIDefaults table = new MyDefaults();
             Object[] uiDefaults = {
                "ButtonUI", (isModInstalled ? "MyModButtonUI" : "MyAuxButtonUI"),
             table.putDefaults(uiDefaults);
             return table;
       class MyDefaults extends UIDefaults {
          protected void getUIError(String msg) {
    //         System.err.println("(Not) An annoying error message!");
    }File MyAuxButtonUI.java:
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.plaf.*;
    import javax.swing.plaf.multi.*;
    import javax.accessibility.*;
    public class MyAuxButtonUI extends ButtonUI {
       private Color background;
       private Color foreground;
       private ButtonUI ui = null;
       public static ComponentUI createUI( JComponent c ) {
          return new MyAuxButtonUI();
       public void installUI(JComponent c) {
          MultiButtonUI multiButtonUI = (MultiButtonUI) UIManager.getUI(c);
          this.ui = (ButtonUI) (multiButtonUI.getUIs()[0]);
          super.installUI( c );
          background = c.getBackground();
          foreground = c.getForeground();
          c.setBackground(Color.GREEN);
          c.setForeground(Color.RED);
       public void uninstallUI(JComponent c) {
          super.uninstallUI( c );
          c.setBackground(background);
          c.setForeground(foreground);
          this.ui = null;
       public void paint(Graphics g, JComponent c) {
          this.ui.paint( g, c );
       public void update(Graphics g, JComponent c) {
          this.ui.update( g, c );
       public Dimension getPreferredSize(JComponent c) {
          if ( this.ui == null ) {
             return super.getPreferredSize( c );
          return this.ui.getPreferredSize( c );
       public Dimension getMinimumSize(JComponent c) {
          if ( this.ui == null ) {
             return super.getMinimumSize( c );
          return this.ui.getMinimumSize( c );
       public Dimension getMaximumSize(JComponent c) {
          if ( this.ui == null ) {
             return super.getMaximumSize( c );
          return this.ui.getMaximumSize( c );
       public boolean contains(JComponent c, int x, int y) {
          if ( this.ui == null ) {
             return super.contains( c, x, y );
          return this.ui.contains( c, x, y );
       public int getAccessibleChildrenCount(JComponent c) {
          if ( this.ui == null ) {
             return super.getAccessibleChildrenCount( c );
          return this.ui.getAccessibleChildrenCount( c );
       public Accessible getAccessibleChild(JComponent c, int ii) {
          if ( this.ui == null ) {
             return super.getAccessibleChild( c, ii );
          return this.ui.getAccessibleChild( c, ii );
    }File MyModButtonUI.java:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.plaf.*;
    public class MyModButtonUI extends MyAuxButtonUI
       static KeyStroke spaceKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0 );
       public static ComponentUI createUI( JComponent c ) {
          return new MyModButtonUI();
       public void installUI(JComponent c) {
          super.installUI(c);
          c.setBackground(Color.CYAN);
          if ( c.isFocusable() ) {
             c.setFocusable(true);
    //      final JButton button = (JButton) c;
    //      button.getInputMap().put( spaceKeyStroke, "buttonexample.pressed" );
    //      button.getActionMap().put( "buttonexample.pressed", new AbstractAction() {
    //         public void actionPerformed(ActionEvent e) {
    //            button.doClick();
    //   public void uninstallUI(JComponent c) {
    //      super.uninstallUI(c);
    //      JButton button = (JButton) c;
    //      button.getInputMap().remove( spaceKeyStroke );
    //      button.getActionMap().remove( "buttonexample.pressed" );
    }

    here is the code used to change the current look and feel :
    try {
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
             catch (InstantiationException e)
                  System.out.println("Error occured  "+ e.toString());
             catch (ClassNotFoundException e)
                  System.out.println("Error occured  "+ e.toString());
             catch (UnsupportedLookAndFeelException e)
                  System.out.println("Error occured  "+ e.toString());
             catch (IllegalAccessException e)
                  System.out.println("Error occured in .. " + e.toString());
             Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
             Fenetre fen = new Fenetre();
             fen.setSize(dim.width, dim.height);
             fen.setResizable(false);
                 fen.setLocation(0, 0);
                  fen.setVisible(true);

  • Customisin Look and Feel

    I am still in the process of "finding my feet" when it comes to programming with Java, and as a result need a little guidance.
    Could anyone please tell me of a good place to find information that offers tutorials or good explanations of how to customize the look and feel of JComponents in swing.
    Much appreciated,
    Craig.

    Take a look at the java source code for the SwingSet2 demo that comes with the java plugin...it's exactly what you need.

  • JTree Button, Line and Java look and feel ?

    Hi all,
    I have 3 small problem with my JTree ..
    1) The 'expand' button size ...
    I set a different Icon for each node in a getTreeCellRendererComponent method (from a class that extends DefaultTreeCellRenderer )...
    The icon are 32x32 pixels.. .and the RowHeight and the Font have been changed too. .
    How to change the size of the expand button (+/-) near the text node ? Because on my JTree, the expand/collapse buttons are really small compare to the icon & row height.
    2) No line appear between the node ...
    I try to set the line style property with -> putClientProperty("JTree.lineStyle", "Angled"); in the JTree constructor OR in the DefaultTreeCellRenderer constructor .. but it doesn't work :/
    3) How to set a Java look and feel for my JTree (actually, I have a Windows look and feel ..)
    I know .. I have grouped 3 question in the same topic ...
    If anyone can help me on one of these subjects. .. Thanks !
    Regards,
    Didier

    So, the Problem 1) is solved ..
    About the Problem 2)
    I put the code UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel()) in the main method, like
      //Main method
      public static void main(String[] args) {
        try {
          UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
        catch(Exception e) {
          e.printStackTrace();
        new MainApplication();
      }But it only set a Java L&F on the spliter, and on the toolbar contained in my application... Any idea why the title bar is not changed too ?
    (The title bar stay with a Window$ XP L&F ...)
    About the problem 3)
    When I set the L&F->UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); then the lines appear .. ??!! .. if I set again the previous value UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); .. then the lines desappear ..

  • Changing look and feel with radio buttons

    k this is the code that i have so far, Yes i read the tutorial and stuff but it doesnt seem to make any sense and all. tell me what else i need in this code to do what i want, its the action performed part i didnt put the other code, what else do i need??? but well...you will see grips of duke dollars to whom can do it
    public void actionPerformed(ActionEvent e)
    String actionCommand = e.getActionCommand();
    if(actionCommand.equals("Metal"))
    try
    UIManager.setLookAndFeel( "javax.swing.plaf.metal.MetalLookAndFeel" );
    catch (Exception ex)
    else if(actionCommand.equals("Windows"))
    try
    UIManager.setLookAndFeel( "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
    catch (Exception ex)
    else if(actionCommand.equals("Motif"))
    try
    UIManager.setLookAndFeel( "com.sun.java.swing.plaf.motif.MotifLookAndFeel");
    catch (Exception ex)
    }

    While not in the tutorial, I have found several other things necessary to get the look and feel change to be complete. Here is the code I'm using after I set the look and feel. It seems to do a pretty good job of sync'ing everything together.
                SwingUtilities.updateComponentTreeUI(TDba.getFrame());
                TDba.getFrame().pack();
                Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                Integer w = new Integer((int)(dim.width * .8));
                Integer h = new Integer((int)(dim.height * .8));           
                TDba.getFrame().setSize(w.intValue(), h.intValue());
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Swing: Look and Feel

    I've found this page with a nice look and feel:
    https://substance.dev.java.net/docs/skins.html#CremeSkin
    But I can't use it.
    I import this:
    import org.jvnet.substance.skin.SubstanceCremeLookAndFeel;
    And do this:
    UIManager.setLookAndFeel(new SubstanceCremeLookAndFeel());
    But the import-libary are not correct. Hope somebody can help me! I'm using netBeans.

    you can add LAF without changing of code. Start app from command line like this
    @call set_classpath.bat
    @set classpath=../../laf/substance.jar;%classpath%
    @java -Dswing.defaultlaf=org.jvnet.substance.SubstanceLookAndFeel myPkg.myApp
    see quick review of LAF's - http://sss1024.googlepages.com/

  • Swing disabled components look and feel problem.

    Hi All,
    I have a Swing application. My system is recently upgraded to JRE 1.6 and I'm facing problem with look and feel of swing components when they are disabled. Color of disabled components is very faint and its being difficult to read the text in such disabled components. In JRE 1.4 this problem was not there. Please let me know what I can do to get the look and feel(Color and Font) of disabled components, same as JRE 1.4.
    Thanks

    Sandip_Jarad wrote:
    ..I have a Swing application. My system is recently upgraded to JRE 1.6 and I'm facing problem with look and feel of swing components when they are disabled. Which look and feel is the application using? As an aside, did it never occur to you to mention the PLAF?
    ..Color of disabled components is very faint and its being difficult to read the text in such disabled components. Why is it so gosh-darned important to read the text on a control that is (supposedly) not relevant or not available?
    ..In JRE 1.4 this problem was not there. Please let me know what I can do to get the look and feel(Color and Font) of disabled components, same as JRE 1.4. Here are some suggestions, some of them are actually serious. I'll leave it as an exercise for you, to figure out which ones.
    - Run the app. in 1.4.
    - Use a custom PLAF that offers a 'less faint' rendering of disabled components.
    - Use Motif PLAF (I haven't checked, but I bet that has not changed since 1.4).
    - Put the important text in a tool-tip.

  • Push Button look and feel

    Hi,
    I am using forms 10g
    I have a requirement to make the look and feel of the push button like a hyperlink.
    Basically the button background should merge with the canvas background and text should appear on the canvas.
    I have to use push buttons only as i have a require setting mouse navigate property for the buttons to function correctly.
    I tried using image instead of buttons but image does not have mouse navigate property.
    kindly reply as this is becoming a show stopper fr the proposed look and feel in the current project.
    Edited by: user3067156 on May 4, 2010 6:01 AM

    One use case for setting mouse navigate property to yes is mentioned in this link
    http://www.oracle.com/technology/obe/obe_as_10g/bi/forms/formsmasterdetailobe.htm
    When Mouse Navigate is No, Form Builder does not perform navigation to the item when the end user activates it with the mouse. For example, a mouse click in a button or check box is not treated as a navigational event.
    Form Builder fires any triggers defined for the button or check box (such as When-Button-Pressed), but the input focus remains in the current item.
    When Mouse Navigate is Yes, Form Builder navigates to the item, firing any appropriate navigation and validation triggers on the way.
    if the button performs query or cancel mouse navigate is set to No
    if the button performs first ,next, commit record mouse navigate is set to Yes.

  • Drawing window borders swing look and feel

    Does anyone know how to change the frame window border from being drawn in the windows look and feel? I want them to be drawn as a swing application. Can anyone help?

    Frames (and JFrames) are top-level containers that are not subject to rendering by the Look-and-Feel manager (they are actually "heavy-weight" native components). However, in 1.4 it is possible to use an undecorated frame (using Frame.setUndecorated(true)) which you could paint to look like a JInternalFrame. However, I think you lose the automatic handling of resizing, moving, iconifying, maximizing, closing, etc.

  • Handle to Look and feel scrollbdown button icon possible?

    Is there any way to get handle to the Look and feel scrollbdown button icon ( an arrow pointing down) programmatically?

    Not in a simple way, AFAIK. You'll probably have to override the corresponding plaf UI delegate to do that.

  • Look and Feel

    Salutations,
    I am writing a simple swing program that when the user clicks a button corresponding to a look and feel name ie "Metal" etc. the Look and Feel is Changed, it works great except for one problem, it will not change to the "Metal" look and feel, I believe this to be the default look and feel, but when changed to another, it will not change back. Any suggestions?
    thanks,
    J

    Here's the code from the SwingSet2 Demo:
    // Possible Look & Feels
        private static final String mac      = "com.sun.java.swing.plaf.mac.MacLookAndFeel";
        private static final String metal    = "javax.swing.plaf.metal.MetalLookAndFeel";
        private static final String motif    = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
        private static final String windows  = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
            try {
                UIManager.setLookAndFeel(currentLookAndFeel);
                SwingUtilities.updateComponentTreeUI(this);
                // where currentLookAndFeel is one of those Strings
            } catch (Exception ex) {
             System.out.println("Failed loading L&F: " + currentLookAndFeel);
             System.out.println(ex);
    // And as an (unexpected) bonus, it's the same as the code I once used:
    static String windowsClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
            try
                javax.swing.UIManager.setLookAndFeel(windowsClassName);
                javax.swing.SwingUtilities.updateComponentTreeUI(this);
            catch(Exception e)

  • 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));

  • How to customize the title bar on my own Look And Feel?

    Hi all!
    I am creating my own Look and Feel which extends from NimbusLookAndFeel. What I'm doing is overwriting UIDefaults values??, referring to the Painters. For example:
    +uiDefault.put ("Button [Enabled]", new ButtonEnabledPainter());+
    But now I need is to customize the title bar of the JFrame's, but I do not see this option in Painter's values ??can be overwritten by Nimbus (http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults . html).
    You know as possible? I have to overwrite an existing UI component? The idea is I want to make the look and feel like SeaGlass, but the code seems a bit complex to know where to begin.
    I hope you can guide me on this issue.
    Thank you very much for everything! And excuse my English!.
    Greetings!

    very simple example, with direct methods
    import java.awt.*;
    import java.awt.event.*;
    import java.util.LinkedList;
    import java.util.Queue;
    import javax.swing.*;
    public class NimbusBorderPainterDemo extends JFrame {
        private static final long serialVersionUID = 1L;
        private JFrame frame = new JFrame();
        private JPanel fatherPanel = new JPanel();
        private JPanel contentPanel = new JPanel();
        private GradientPanel titlePanel = new GradientPanel(Color.BLACK);
        private JLabel buttonPanel = new JLabel();
        private Queue<Icon> iconQueue = new LinkedList<Icon>();
        public NimbusBorderPainterDemo() {
            iconQueue.add(UIManager.getIcon("OptionPane.errorIcon"));
            iconQueue.add(UIManager.getIcon("OptionPane.informationIcon"));
            iconQueue.add(UIManager.getIcon("OptionPane.warningIcon"));
            iconQueue.add(UIManager.getIcon("OptionPane.questionIcon"));
            JButton button0 = createButton();
            button0.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    frame.setExtendedState(ICONIFIED);
            JButton button1 = createButton();
            button1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    frame.setExtendedState(MAXIMIZED_BOTH | NORMAL);
                }//quick implemented, not correct you have to override both methods
            JButton button2 = createButton();
            button2.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    int confirm = JOptionPane.showOptionDialog(frame,
                            "Are You Sure to Close Application?", "Exit Confirmation",
                            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
                            null, null, null);
                    if (confirm == JOptionPane.YES_OPTION) {
                        System.exit(1);
            buttonPanel.setLayout(new GridLayout(0, 3, 5, 0));
            buttonPanel.setPreferredSize(new Dimension(160, 30));
            buttonPanel.add(button0);// JLabel is best and cross_platform JComponents
            buttonPanel.add(button1);// not possible put there witouth set Dimmnesion
            buttonPanel.add(button2);// and LayoutManager, work in all cases better
            titlePanel.setLayout(new BorderLayout());//than JPanel or JCompoenent
            titlePanel.add(new JLabel(nextIcon()), BorderLayout.WEST);
            titlePanel.add(new JLabel("My Frame"), BorderLayout.CENTER);
            titlePanel.setBorder(BorderFactory.createLineBorder(Color.GRAY));
            titlePanel.add(buttonPanel, BorderLayout.EAST);
            JTextField field = new JTextField(50);
            JButton btn = new JButton("Close Me");
            btn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.exit(1);
            contentPanel.add(field);
            contentPanel.add(btn);
            fatherPanel.setLayout(new BorderLayout());
            fatherPanel.add(titlePanel, BorderLayout.NORTH);
            fatherPanel.add(contentPanel, BorderLayout.CENTER);
            frame.setUndecorated(true);
            frame.add(fatherPanel);
            frame.setLocation(50, 50);
            frame.pack();
            frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            frame.setVisible(true);
            ComponentMover cm = new ComponentMover(frame, titlePanel);
            //by camickr http://tips4java.wordpress.com/2009/06/14/moving-windows/
        private JButton createButton() {
            JButton button = new JButton();
            button.setBorderPainted(false);
            button.setBorder(null);
            button.setFocusable(false);
            button.setMargin(new Insets(0, 0, 0, 0));
            button.setContentAreaFilled(false);
            button.setIcon(nextIcon());
            button.setRolloverIcon(nextIcon());
            button.setPressedIcon(nextIcon());
            button.setDisabledIcon(nextIcon());
            nextIcon();
            return button;
        private Icon nextIcon() {
            Icon icon = iconQueue.peek();
            iconQueue.add(iconQueue.remove());
            return icon;
        private class GradientPanel extends JPanel {
            private static final long serialVersionUID = 1L;
            public GradientPanel(Color background) {
                setBackground(background);
            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if (isOpaque()) {
                    Color background = new Color(168, 210, 241);
                    Color controlColor = new Color(230, 240, 230);
                    int width = getWidth();
                    int height = getHeight();
                    Graphics2D g2 = (Graphics2D) g;
                    Paint oldPaint = g2.getPaint();
                    g2.setPaint(new GradientPaint(0, 0, background, width, 0, controlColor));
                    g2.fillRect(0, 0, width, height);
                    g2.setPaint(oldPaint);
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
                    } catch (Exception fail) {
                    UIManager.getLookAndFeelDefaults().put("nimbusFocus", Color.RED);
                    NimbusBorderPainterDemo nimbusBorderPainterDemo = new NimbusBorderPainterDemo();
    }

  • Replacing part of a Look and Feel

    Hi, all,
    I have designed a new UI delegate for buttons (Both command buttons and toggle buttons), ones that fit better with the color palette, gradients, fonts, spacing, icons, borders, etc, that we have been using for much of the rest of our GUI. Up to now, I've been replacing the UI delegate of each button after I create it, but I'd like to do a global replacement of this UI for all buttons that use the default UI delegate. That way, I can still use things like JOptionPane.showXXXMessage(), and those buttons will be updated as well.
    The only way I can find to do this is to write a new Look and Feel, but I only have a new UI delegate for buttons, and I would like for any other JComponents to continue to use the default look and feel (that is, the system native look and feel, or which ever look and feel is set to be used in their properties, etc). Does anybody know of a way to tell the UIManager (or some other component it uses) to use my UI delegate for Buttons, and use it's defaults for everything else? Preferably without writing a new Look and Feel?
    Thanks!
    Adam

    To make all buttons use the BasicButtonUI you set the following:
    UIManager.put("ButtonUI", "javax.swing.plaf.basic.BasicButtonUI");I imagine that you can replace the class name with your own UI. Remember to do this after you set the look and feel.

  • JFileChooser not opening when we applied custom Look and Feel & Theme

    Dear All,
    JFileChooser not opening when we applied custom Look and Feel & Theme.
    The following is the source code
    import java.awt.Color;
    import javax.swing.*;
    import javax.swing.plaf.ColorUIResource;
    import javax.swing.plaf.metal.MetalLookAndFeel;
    import com.jgoodies.looks.plastic.*;
    public class CustomTheme {
    public static void main(String[] args)throws UnsupportedLookAndFeelException{
    UIManager.setLookAndFeel(new MyLookAndFeel());
    MyLookAndFeel.setCurrentTheme(new CustomLaF());
    JFrame frame = new JFrame("Metal Theme");
    JFileChooser jf = new JFileChooser();
    System.out.println("UI - > "+jf.getUI());
    //jf.updateUI();
    frame.getContentPane().add(jf);
    frame.pack();
    frame.setVisible(true);
    static class CustomLaF extends PlasticTheme {
    protected ColorUIResource getPrimary1() {
    return new ColorUIResource(232,132,11);
    public ColorUIResource getPrimary2() {
              return (new ColorUIResource(Color.white));
         public ColorUIResource getPrimary3() {
              return (new ColorUIResource(232,132,11));
    public ColorUIResource getPrimaryControl() {
    return new ColorUIResource(Color.GREEN);
    protected ColorUIResource getSecondary1() {
    return new ColorUIResource(Color.CYAN);
    protected ColorUIResource getSecondary2() {
              return (new ColorUIResource(Color.gray));
         protected ColorUIResource getSecondary3() {
              return (new ColorUIResource(235,235,235));
         protected ColorUIResource getBlack() {
              return BLACK;
         protected ColorUIResource getWhite() {
              return WHITE;
    static class MyLookAndFeel extends Plastic3DLookAndFeel {
              protected void initClassDefaults(UIDefaults table) {
                   super.initClassDefaults(table);
              protected void initComponentDefaults(UIDefaults table) {
                   super.initComponentDefaults(table);
                   Object[] defaults = {
                             "MenuItem.foreground",new ColorUIResource(Color.white),
                             "MenuItem.background",new ColorUIResource(Color.gray),
                             "MenuItem.selectionForeground",new ColorUIResource(Color.gray),
                             "MenuItem.selectionBackground",new ColorUIResource(Color.white),
                             "Menu.selectionForeground", new ColorUIResource(Color.white),
                             "Menu.selectionBackground", new ColorUIResource(Color.gray),
                             "MenuBar.background", new ColorUIResource(235,235,235),
                             "Menu.background", new ColorUIResource(235,235,235),
                             "Desktop.background",new ColorUIResource(235,235,235),
                             "Button.select",new ColorUIResource(232,132,11),
                             "Button.focus",new ColorUIResource(232,132,11),
                             "TableHeader.background", new ColorUIResource(232,132,11),
                             "TableHeader.foreground", new ColorUIResource(Color.white),
                             "ScrollBar.background", new ColorUIResource(235,235,235),
                             "ToolTip.foreground", new ColorUIResource(232,132,11),
                             "ToolTip.background", new ColorUIResource(Color.white),
                             "OptionPane.questionDialog.border.background", new ColorUIResource(Color.gray),
                             "OptionPane.errorDialog.titlePane.foreground", new ColorUIResource(Color.white),
                             "OptionPane.questionDialog.titlePane.background", new ColorUIResource(232,132,11),
                             "Table.selectionBackground", new ColorUIResource(232,132,11)
                   table.putDefaults(defaults);
    When i run this program the following error is coming:
    Exception in thread "main" java.lang.NullPointerException
    at javax.swing.plaf.metal.MetalFileChooserUI$IndentIcon.getIconWidth(Unknown Source)
    at javax.swing.SwingUtilities.layoutCompoundLabelImpl(Unknown Source)
    at javax.swing.SwingUtilities.layoutCompoundLabel(Unknown Source)
    at javax.swing.plaf.basic.BasicLabelUI.layoutCL(Unknown Source)
    at javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(Unknown Source)
    at javax.swing.JComponent.getPreferredSize(Unknown Source)
    at javax.swing.plaf.basic.BasicListUI.updateLayoutState(Unknown Source)
    at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(Unknown Source)
    at javax.swing.plaf.basic.BasicListUI$ListSelectionHandler.valueChanged(Unknown Source)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
    at javax.swing.DefaultListSelectionModel.changeSelection(Unknown Source)
    at javax.swing.DefaultListSelectionModel.changeSelection(Unknown Source)
    at javax.swing.DefaultListSelectionModel.setSelectionInterval(Unknown Source)
    at javax.swing.JList.setSelectedIndex(Unknown Source)
    at javax.swing.plaf.basic.BasicComboPopup.setListSelection(Unknown Source)
    at javax.swing.plaf.basic.BasicComboPopup.access$000(Unknown Source)
    at javax.swing.plaf.basic.BasicComboPopup$ItemHandler.itemStateChanged(Unknown Source)
    at javax.swing.JComboBox.fireItemStateChanged(Unknown Source)
    at javax.swing.JComboBox.selectedItemChanged(Unknown Source)
    at javax.swing.JComboBox.contentsChanged(Unknown Source)
    at javax.swing.AbstractListModel.fireContentsChanged(Unknown Source)
    at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxModel.setSelectedItem(Unknow
    at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxModel.addItem(Unknown Source
    at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxModel.access$2300(Unknown So
    at javax.swing.plaf.metal.MetalFileChooserUI.doDirectoryChanged(Unknown Source)
    at javax.swing.plaf.metal.MetalFileChooserUI.access$2600(Unknown Source)
    at javax.swing.plaf.metal.MetalFileChooserUI$12.propertyChange(Unknown Source)
    at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(Unknown Source)
    at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(Unknown Source)
    at javax.swing.JComponent.firePropertyChange(Unknown Source)
    at javax.swing.JFileChooser.setCurrentDirectory(Unknown Source)
    at javax.swing.JFileChooser.<init>(Unknown Source)
    at javax.swing.JFileChooser.<init>(Unknown Source)
    at CustomTheme.main(CustomTheme.java:20)
    I am extending the JGoodies Look And Feel & Theme.
    Thanks in advance
    Krishna Mohan.

    Dear cupofjoe,
    Thank you for your response.
    I am using the Latest JGoodies Look & Feel which is downloaded from http://www.jgoodies.com.
    i am writing our own custom Look & Feel By Overridding Jgoodies Look & Feel.
    In that case i am getting that error.
    The following is the source code:
    import java.awt.Color;
    import javax.swing.*;
    import javax.swing.plaf.ColorUIResource;
    import javax.swing.plaf.metal.MetalLookAndFeel;
    import com.jgoodies.looks.plastic.*;
    public class CustomTheme {
    public static void main(String[] args)throws UnsupportedLookAndFeelException{
    UIManager.setLookAndFeel(new MyLookAndFeel());
    MyLookAndFeel.setCurrentTheme(new CustomLaF());
    JFrame frame = new JFrame("Metal Theme");
    JFileChooser jf = new JFileChooser();
    //System.out.println("UI - > "+jf.getUI());
    //jf.updateUI();
    //frame.getContentPane().add(jf);
    frame.pack();
    frame.setVisible(true);
    static class CustomLaF extends PlasticTheme {
    protected ColorUIResource getPrimary1() {
    return new ColorUIResource(232,132,11);
    public ColorUIResource getPrimary2() {
              return (new ColorUIResource(Color.white));
         public ColorUIResource getPrimary3() {
              return (new ColorUIResource(232,132,11));
    public ColorUIResource getPrimaryControl() {
    return new ColorUIResource(Color.GREEN);
    protected ColorUIResource getSecondary1() {
    return new ColorUIResource(Color.CYAN);
    protected ColorUIResource getSecondary2() {
              return (new ColorUIResource(Color.gray));
         protected ColorUIResource getSecondary3() {
              return (new ColorUIResource(235,235,235));
         protected ColorUIResource getBlack() {
              return BLACK;
         protected ColorUIResource getWhite() {
              return WHITE;
    static class MyLookAndFeel extends Plastic3DLookAndFeel {
              protected void initClassDefaults(UIDefaults table) {
                   super.initClassDefaults(table);
              protected void initComponentDefaults(UIDefaults table) {
                   super.initComponentDefaults(table);
                   Object[] defaults = {
                             "MenuItem.foreground",new ColorUIResource(Color.white),
                             "MenuItem.background",new ColorUIResource(Color.gray),
                             "MenuItem.selectionForeground",new ColorUIResource(Color.gray),
                             "MenuItem.selectionBackground",new ColorUIResource(Color.white),
                             "Menu.selectionForeground", new ColorUIResource(Color.white),
                             "Menu.selectionBackground", new ColorUIResource(Color.gray),
                             "MenuBar.background", new ColorUIResource(235,235,235),
                             "Menu.background", new ColorUIResource(235,235,235),
                             "Desktop.background",new ColorUIResource(235,235,235),
                             "Button.select",new ColorUIResource(232,132,11),
                             "Button.focus",new ColorUIResource(232,132,11),
                             "TableHeader.background", new ColorUIResource(232,132,11),
                             "TableHeader.foreground", new ColorUIResource(Color.white),
                             "ScrollBar.background", new ColorUIResource(235,235,235),
                             "ToolTip.foreground", new ColorUIResource(232,132,11),
                             "ToolTip.background", new ColorUIResource(Color.white),
                             "OptionPane.questionDialog.border.background", new ColorUIResource(Color.gray),
                             "OptionPane.errorDialog.titlePane.foreground", new ColorUIResource(Color.white),
                             "OptionPane.questionDialog.titlePane.background", new ColorUIResource(232,132,11),
                             "Table.selectionBackground", new ColorUIResource(232,132,11)
                   table.putDefaults(defaults);
    pls suggest me the how to solve this problem.
    thanks in advance
    Krishna MOhan

Maybe you are looking for

  • Publish iweb from another computer what am I doing wrong?

    I am really struggling here, can someone please explain my problem to me.... I have two mac laptops with iweb. I asked about publishing my backed up blog on the 2nd mac in case number 1 mac crashes. here was my question... how does the new computer k

  • How can i get a filename?

    I have some files on linux, I need to get their names and checks if the word that I search exists in the filename or not? if it does, I will copy the file as a different name. If it doesn't i will raise an error. I want to do that using pl/sql, is th

  • Muse lightbox widget

    I want to use the lightbox widget with an initial picture and then I want to have other pictures that are stacked and triggered to display when the mouse hovers over the thumbnail trigger. When the mouse is not over one of the triggers i want the ini

  • Flickering Video Final Cut Express

    Hi! There is a fair amount of flickering when I do cross-fades manually (with superimpositions) on Final Cut Express (the version I have is at least a couple of years old), and I was wondering whether it was playback quality or whether it is somethin

  • Adobe Elements5

    I had to reinstall my Adobe Photoshop Elements 5.0 but my computer won't recognize the disk.  I used the run command.  Is there anything I can do?