SwingUtilities.updateComponentTreeUI()

hello everybody,
can you please have a look at this?
probably I posted the problem in the wrong forum first, so here is the link:
http://forum.java.sun.com/thread.jspa?threadID=753965
thanks a lot

As it is usually called when changing the look & feel, I guess the new L & F wishes to ensure the key mappings are setup back to default...

Similar Messages

  • Problem with SwingUtilities.UpdateComponentTreeUI(component c)

    I have a Action class and I wrote swingutilities.updatecomponenttreeui in its actonperformed method.
    I passed a panel class as its argument but it dose not do anything!
    any clue?

    the code is at http://forums.java.sun.com/thread.jsp?forum=54&thread=178648

  • Getting error in SwingUtilities.updateComponentTreeUI

    Hi to all,
    I am writint a application.In it I am calling my main application window through another calss called ftp.JFrame(user defined calss)
    like
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    //code here
    new mainApplication();
    and in my mainApplication class I am writing whole code for displaying frame.I am trying to set LookAndFeel but it is giving error.
    private void gtkActionPerformed(java.awt.event.ActionEvent evt) {
    lookandfeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
    private void windowsActionPerformed(java.awt.event.ActionEvent evt) {
    lookandfeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    .........//in between code
    and method lookandfeel() is
    public void lookandfeel(String landf){   
    String s = new String();
    final JFrame root=this;
    //final JFrame root=new JFrame();
    //final mainApplication root=new mainApplication();
    try
    s=landf;
    System.out.println(s);
    UIManager.setLookAndFeel(s);
    SwingUtilities.updateComponentTreeUI(root);
    /*SwingUtilities.invokeLater(new Runnable() {
    public void run() { SwingUtilities.updateComponentTreeUI(root); }
    catch(Exception e)
    System.out.println("Exception ..."+e);
    but after displaying the mainApplication when I am clicking on gtkActionPerformed (Event ..)
    it is setting exact LookAndFeel but after again clicking the same button it is giving the following error
    =====================================================
    java.lang.NullPointerException
    at javax.swing.plaf.basic.BasicPopupMenuUI$MenuKeyboardHelper.addUIInput
    Map(BasicPopupMenuUI.java:843)
    at javax.swing.plaf.basic.BasicPopupMenuUI$MenuKeyboardHelper.stateChang
    ed(BasicPopupMenuUI.java:960)
    at javax.swing.MenuSelectionManager.fireStateChanged(MenuSelectionManage
    r.java:158)
    at javax.swing.MenuSelectionManager.setSelectedPath(MenuSelectionManager
    .java:86)
    at com.sun.java.swing.plaf.gtk.SynthMenuUI$MouseInputHandler.mousePresse
    d(SynthMenuUI.java:313)
    at java.awt.Component.processMouseEvent(Component.java:5090)
    at java.awt.Component.processEvent(Component.java:4890)
    at java.awt.Container.processEvent(Container.java:1566)
    at java.awt.Component.dispatchEventImpl(Component.java:3598)
    at java.awt.Container.dispatchEventImpl(Container.java:1623)
    at java.awt.Component.dispatchEvent(Component.java:3439)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3162)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
    at java.awt.Container.dispatchEventImpl(Container.java:1609)
    at java.awt.Window.dispatchEventImpl(Window.java:1585)
    at java.awt.Component.dispatchEvent(Component.java:3439)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:197)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
    ====================================================================
    Please help me to trace out this problem.
    Any help is usefull for me.
    Thanks in advance

    Hi Maninder Singh Golar,
    Thanks for visiting Apple Support Communities.
    If you can use your Apple ID to sign into the iTunes Store, but not iCloud, see this article for some troubleshooting tips that can help:
    iCloud: Account troubleshooting
    http://support.apple.com/kb/TS3988
    Cheers,
    Jeremy

  • Is SwingUtilities.updateComponentTreeUI necessary?

    I have a drawing program, thew main porgram of which extends JFrame, which contains a canvas, which extends JPanel. I set my look-and-feel as:
    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()).
    Originally, after setting my look-and-feel, I said:
    SwingUtilities.updateComponentTreeUI(this).
    However the call of SwingUtilities.updateComponentTreeUI had the following effect:
    When my focus is in the canvas and I press the ALT key, which is recognized in my KeyAdapter of my canvas, my mouse clicks in the MouseAdapter of my canvas don't get recognized anymore.
    However, I need the mouse clicks to be recognizable, because when I am in zoom mode in my drawing program, pressing the ALT key and clicking the mouse does the zooming out action.
    My question is: Is it okay to comment the call of SwingUtilities.updateComponentTreeUI out, or is this call necessary.
    Thanks in advance for your answer!

    Bridge,
    I didn't understand your code.
    Could you please explain again in more detail?If I understand my_second_favourite_crossdressing_uncle correctly he means that it's NOT a good habit to do things like...
    class Something {
      JFrame frame = new Frame();
      Something() {
      // it's too late to change the L&F coz you've already instantiated a JFrame when the class was loaded
      UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName())
      }... because you are needlessly obfiscating the timing of when objects are created in relation to the execution remainder of your code... which doesn't usually matter at all, except when it's vital, such as this case... and it's usually not to hard to figure out the problem in instances of the first example, but it's almost impossible to track down in instances "in the order of" the second example (which creates a class which creates a Swing control before calling setLookAndFeel... extra especially when YOU didn't write the code.
    ie... I makes swing apps just a harder less flexible, and trickier to maintain, with no advantages... so please don't do it.
    Edited by: corlettk on Nov 26, 2007 2:09 PM - fraggin code tags

  • SwingUtilities throwing Null Exception

    I created the following class to report a bug and came across something interesting:
    // Instructions to view bug
    // 1) On your favorite windows operated machine (xp in my case) unlock and move your taskbar
    //    so that it is along the left pane of your screen.
    // 2) Run the following java program
    // 3) Maximize the BugCheck window
    // 4) Click on the down arrow of the combobox
    // 5) You will see the combobox is not dropping to where it should and the dropdown selection text is cutoff.
    package com.BugCheck;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    * This simple class will demonstrate a jcombobox being misaligned
    * when selected and the user's Windows taskbar is along the LEFT
    * side of the screen.
    public class BugCheck extends JFrame
        public BugCheck()
            try
                jbInit();
            } catch (Exception ex)
                ex.printStackTrace();
        public static void main(String args[])
            BugCheck f = new BugCheck();
            f.setSize(new Dimension(100, 100));
            f.setVisible(true);
            try {
                UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                SwingUtilities.updateComponentTreeUI(f);
            } catch (Exception e ) {
                e.printStackTrace();
        private void jbInit() throws Exception
            jComboBox1.addItem("Selection 1");
            jComboBox1.addItem("Selection 2");
            jComboBox1.addItem("Can't");
            jComboBox1.addItem("see");
            jComboBox1.addItem("this.");
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setTitle("BugCheck");
            this.getContentPane().add(jComboBox1, java.awt.BorderLayout.NORTH);
        JComboBox jComboBox1 = new JComboBox();
    }I got the exceptions listed below, and after some fiddling it turns out the culprit is the following line of code. When commented out, the exceptions do not happen.
    this.getContentPane().add(jComboBox1, java.awt.BorderLayout.NORTH);is causing these exceptions to be thrown:
    "C:\Program Files\Java\j2re1.4.2_07\bin\javaw" -classpath "H:\BugCheck\classes;C:\Program Files\Java\j2re1.4.2_07\javaws\javaws.jar;C:\Program Files\Java\j2re1.4.2_07\lib\charsets.jar;C:\Program Files\Java\j2re1.4.2_07\lib\ext\dnsns.jar;C:\Program Files\Java\j2re1.4.2_07\lib\ext\ldapsec.jar;C:\Program Files\Java\j2re1.4.2_07\lib\ext\localedata.jar;C:\Program Files\Java\j2re1.4.2_07\lib\ext\sunjce_provider.jar;C:\Program Files\Java\j2re1.4.2_07\lib\im\indicim.jar;C:\Program Files\Java\j2re1.4.2_07\lib\im\thaiim.jar;C:\Program Files\Java\j2re1.4.2_07\lib\jce.jar;C:\Program Files\Java\j2re1.4.2_07\lib\jsse.jar;C:\Program Files\Java\j2re1.4.2_07\lib\plugin.jar;C:\Program Files\Java\j2re1.4.2_07\lib\rt.jar;C:\Program Files\Java\j2re1.4.2_07\lib\sunrsasign.jar"  com.BugCheck.BugCheck
    java.lang.NullPointerException
         at javax.swing.DefaultListCellRenderer.getListCellRendererComponent(Unknown Source)
         at javax.swing.plaf.basic.BasicComboBoxUI.getDisplaySize(Unknown Source)
         at javax.swing.plaf.basic.BasicComboBoxUI.getMinimumSize(Unknown Source)
         at javax.swing.plaf.basic.BasicComboBoxUI.getPreferredSize(Unknown Source)
         at javax.swing.JComponent.getPreferredSize(Unknown Source)
         at java.awt.BorderLayout.layoutContainer(Unknown Source)
         at java.awt.Container.layout(Unknown Source)
         at java.awt.Container.doLayout(Unknown Source)
         at java.awt.Container.validateTree(Unknown Source)
         at java.awt.Container.validateTree(Unknown Source)
         at java.awt.Container.validateTree(Unknown Source)
         at java.awt.Container.validate(Unknown Source)
         at javax.swing.RepaintManager.validateInvalidComponents(Unknown Source)
         at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    java.lang.NullPointerException
         at javax.swing.plaf.basic.BasicComboBoxUI.isPopupVisible(Unknown Source)
         at javax.swing.plaf.basic.BasicComboBoxUI.paintCurrentValue(Unknown Source)
         at javax.swing.plaf.basic.BasicComboBoxUI.paint(Unknown Source)
         at javax.swing.plaf.ComponentUI.update(Unknown Source)
         at javax.swing.JComponent.paintComponent(Unknown Source)
         at javax.swing.JComponent.paint(Unknown Source)
         at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
         at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
         at javax.swing.JComponent._paintImmediately(Unknown Source)
         at javax.swing.JComponent.paintImmediately(Unknown Source)
         at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
         at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)Any comments?

    Some thoughts, 1) eliminate all those unnecessary jar
    files from your classpath 2) add the bin directory of
    the jdk to your PATH variable and call the java
    command directly for simplicity ... 3) Only include
    on your classpath any jar files that you have created
    for your application or 3rd party jar files. In your
    example it doesn't look like you need to include any
    jar files. 4) I also notice that your package name
    and class name are the same. Generally package names
    are lower case and Class names are upper case.
    java com.bugcheck.BugCheck
    None of these address the issue at hand. Although I do commend you for being nitpicky!
    Suprisingly, running the same program with Java 1.4.2 b5 (the OP was done with 1.4.2 b7) gives more informaton:
    [code
    java.lang.NullPointerException
         at javax.swing.DefaultListCellRenderer.getListCellRendererComponent(DefaultListCellRenderer.java:80)
         at javax.swing.plaf.basic.BasicComboBoxUI.getDisplaySize(BasicComboBoxUI.java:1275)
         at javax.swing.plaf.basic.BasicComboBoxUI.getMinimumSize(BasicComboBoxUI.java:969)
         at javax.swing.plaf.basic.BasicComboBoxUI.getPreferredSize(BasicComboBoxUI.java:959)
         at javax.swing.JComponent.getPreferredSize(JComponent.java:1275)
         at java.awt.BorderLayout.layoutContainer(BorderLayout.java:668)
         at java.awt.Container.layout(Container.java:1020)
         at java.awt.Container.doLayout(Container.java:1010)
         at java.awt.Container.validateTree(Container.java:1092)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validate(Container.java:1067)
         at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:353)
         at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:116)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    java.lang.NullPointerException
         at javax.swing.plaf.basic.BasicComboBoxUI.isPopupVisible(BasicComboBoxUI.java:919)
         at javax.swing.plaf.basic.BasicComboBoxUI.paintCurrentValue(BasicComboBoxUI.java:1148)
         at javax.swing.plaf.basic.BasicComboBoxUI.paint(BasicComboBoxUI.java:954)
         at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)
         at javax.swing.JComponent.paintComponent(JComponent.java:541)
         at javax.swing.JComponent.paint(JComponent.java:808)
         at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4787)
         at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4740)
         at javax.swing.JComponent._paintImmediately(JComponent.java:4685)
         at javax.swing.JComponent.paintImmediately(JComponent.java:4488)
         at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)
         at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:117)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

  • Can someone pls help me with this code

    The method createScreen() creates the first screen wherein the user makes a selection if he wants all the data ,in a range or single data.The problem comes in when the user makes a selection of single.that then displays the singleScreen() method.Then the user has to input a key data like date or invoice no on the basis of which all the information for that set of data is selected.Now if the user inputs a wrong key that does not exist for the first time the program says invalid entry of data,after u click ok on the option pane it prompts him to enter the data again.But since then whenever the user inputs wrong data the program says wrong data but after displaying the singlescreen again does not wait for input from the user it again flashes the option pane with the invalid entry message.and this goes on doubling everytime the user inputs wrong data.the second wrong entry of data flashes the error message twice,the third wrong entry flashes the option pane message 4 times and so on.What actually happens is it does not wait at the singlescreen() for user to input data ,it straight goes into displaying the JOptionPane message for wrong data entry so we have to click the optiion pane twice,four times and so on.
    Can someone pls help me with this!!!!!!!!!
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import java.util.*;
    public class MainMenu extends JFrame implements ActionListener,ItemListener{
    //class     
         FileReaderDemo1 fd=new FileReaderDemo1();
         FileReaderDemo1 fr;
         Swing1Win sw;
    //primary
         int monthkey=1,counter=0;
         boolean flag=false,splitflag=false;
         String selection,monthselection,dateselection="01",yearselection="00",s,searchcriteria="By Date",datekey,smonthkey,invoiceno;
    //arrays
         String singlesearcharray[];
         String[] monthlist={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec"};
         String[] datelist=new String[31];
         String[] yearlist=new String[100];
         String[] searchlist={"By Date","By Invoiceno"};
    //collection
         Hashtable allinvoicesdata=new Hashtable();
         Vector data=new Vector();
         Enumeration keydata;
    //components
         JButton next=new JButton("NEXT>>");
         JComboBox month,date,year,search;
         JLabel bydate,byinvno,trial;
         JTextField yeartext,invtext;
         JPanel panel1,panel2,panel3,panel4;
         JRadioButton single,range,all;
         ButtonGroup group;
         JButton select=new JButton("SELECT");
    //frame and layout declarations
         JFrame jf;
         Container con;
         GridBagLayout gridbag=new GridBagLayout();
         GridBagConstraints gc=new GridBagConstraints();
    //constructor
         MainMenu(){
              jf=new JFrame();
              con=getContentPane();
              con.setLayout(null);
              fr=new FileReaderDemo1();
              createScreen();
              setSize(500,250);
              setLocation(250,250);
              setVisible(true);
    //This is thefirst screen displayed
         public void createScreen(){
              group=new ButtonGroup();
              single=new JRadioButton("SINGLE");
              range=new JRadioButton("RANGE");
              all=new JRadioButton("ALL");
              search=new JComboBox(searchlist);
              group.add(single);
              group.add(range);
              group.add(all);
              single.setBounds(100,50,100,20);
              search.setBounds(200,50,100,20);
              range.setBounds(100,90,100,20);
              all.setBounds(100,130,100,20);
              select.setBounds(200,200,100,20);
              con.add(single);
              con.add(search);
              con.add(range);
              con.add(all);
              con.add(select);
              search.setEnabled(false);
              single.addItemListener(this);
              search.addActionListener(new MyActionListener());     
              range.addItemListener(this);
              all.addItemListener(this);
              select.addActionListener(this);
         public class MyActionListener implements ActionListener{
              public void actionPerformed(ActionEvent a){
                   JComboBox cb=(JComboBox)a.getSource();
                   if(a.getSource().equals(month))
                        monthkey=((cb.getSelectedIndex())+1);
                   if(a.getSource().equals(date)){
                        dateselection=(String)cb.getSelectedItem();
                   if(a.getSource().equals(year))
                        yearselection=(String)cb.getSelectedItem();
                   if(a.getSource().equals(search)){
                        searchcriteria=(String)cb.getSelectedItem();
         public void itemStateChanged(ItemEvent ie){
              if(ie.getItem()==single){
                   selection="single";     
                   search.setEnabled(true);
              else if (ie.getItem()==all){
                   selection="all";
                   search.setEnabled(false);
              else if (ie.getItem()==range){
                   search.setEnabled(false);
         public void actionPerformed(ActionEvent ae){          
              if(ae.getSource().equals(select))
                        if(selection.equals("single")){
                             singleScreen();
                        if(selection.equals("all"))
                             sw=new Swing1Win();
              if(ae.getSource().equals(next)){
                   if(monthkey<9)
                        smonthkey="0"+monthkey;
                   System.out.println(smonthkey+"/"+dateselection+"/"+yearselection+"it prints this");
                   allinvoicesdata=fr.read(searchcriteria);
                   if (searchcriteria.equals("By Date")){
                        System.out.println("it goes in this");
                        singleinvoice(smonthkey+"/"+dateselection+"/"+yearselection);
                   else if (searchcriteria.equals("By Invoiceno")){
                        invoiceno=invtext.getText();
                        singleinvoice(invoiceno);
                   if (flag == false){
                        System.out.println("flag is false");
                        singleScreen();
                   else{
                   System.out.println("its in here");
                   singlesearcharray=new String[data.size()];
                   data.copyInto(singlesearcharray);
                   sw=new Swing1Win(singlesearcharray);
         public void singleinvoice(String searchdata){
              keydata=allinvoicesdata.keys();
              while(keydata.hasMoreElements()){
                        s=(String)keydata.nextElement();
                        if(s.equals(searchdata)){
                             System.out.println(s);
                             flag=true;
                             break;
              if (flag==true){
                   System.out.println("vector found");
                   System.exit(0);
                   data= ((Vector)(allinvoicesdata.get(s)));
              else{
                   JOptionPane.showMessageDialog(jf,"Invalid entry of date : choose again");     
         public void singleScreen(){
              System.out.println("its at the start");
              con.removeAll();
              SwingUtilities.updateComponentTreeUI(con);
              con.setLayout(null);
              counter=0;
              panel2=new JPanel(gridbag);
              bydate=new JLabel("By Date : ");
              byinvno=new JLabel("By Invoice No : ");
              dateComboBox();
              invtext=new JTextField(6);
              gc.gridx=0;
              gc.gridy=0;
              gc.gridwidth=1;
              gridbag.setConstraints(month,gc);
              panel2.add(month);
              gc.gridx=1;
              gc.gridy=0;
              gridbag.setConstraints(date,gc);
              panel2.add(date);
              gc.gridx=2;
              gc.gridy=0;
              gc.gridwidth=1;
              gridbag.setConstraints(year,gc);
              panel2.add(year);
              bydate.setBounds(100,30,60,20);
              con.add(bydate);
              panel2.setBounds(170,30,200,30);
              con.add(panel2);
              byinvno.setBounds(100,70,100,20);
              invtext.setBounds(200,70,50,20);
              con.add(byinvno);
              con.add(invtext);
              next.setBounds(300,200,100,20);
              con.add(next);
              if (searchcriteria.equals("By Invoiceno")){
                   month.setEnabled(false);
                   date.setEnabled(false);
                   year.setEnabled(false);
              else if(searchcriteria.equals("By Date")){
                   byinvno.setEnabled(false);
                   invtext.setEnabled(false);
              monthkey=1;
              dateselection="01";
              yearselection="00";
              month.addActionListener(new MyActionListener());
              date.addActionListener(new MyActionListener());
              year.addActionListener(new MyActionListener());
              next.addActionListener(this);
              invtext.addKeyListener(new KeyAdapter(){
                   public void keyTyped(KeyEvent ke){
                        char c=ke.getKeyChar();
                        if ((c == KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE)){
                             System.out.println(counter+"before");
                             counter--;               
                             System.out.println(counter+"after");
                        else
                             counter++;
                        if(counter>6){
                             System.out.println(counter);
                             counter--;
                             ke.consume();
                        else                    
                        if(!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))){
                             getToolkit().beep();
                             counter--;     
                             JOptionPane.showMessageDialog(null,"please enter numerical value");
                             ke.consume();
              System.out.println("its at the end");
         public void dateComboBox(){          
              for (int counter=0,day=01;day<=31;counter++,day++)
                   if(day<=9)
                        datelist[counter]="0"+String.valueOf(day);
                   else
                        datelist[counter]=String.valueOf(day);
              for(int counter=0,yr=00;yr<=99;yr++,counter++)
                   if(yr<=9)
                        yearlist[counter]="0"+String.valueOf(yr);
                   else
                        yearlist[counter]=String.valueOf(yr);
              month=new JComboBox(monthlist);
              date=new JComboBox(datelist);
              year=new JComboBox(yearlist);
         public static void main(String[] args){
              MainMenu mm=new MainMenu();
         public class WindowHandler extends WindowAdapter{
              public void windowClosing(WindowEvent we){
                   jf.dispose();
                   System.exit(0);
    }     

    Hi,
    I had a similar problem with a message dialog. Don't know if it is a bug, I was in a hurry and had no time to search the bug database... I found a solution by using keyPressed() and keyReleased() instead of keyTyped():
       private boolean pressed = false;
       public void keyPressed(KeyEvent e) {
          pressed = true;
       public void keyReleased(KeyEvent e) {
          if (!pressed) {
             e.consume();
             return;
          // Here you can test whatever key you want
       //...I don't know if it will help you, but it worked for me.
    Regards.

  • JComboBox causing GTK-WARNING and GTK-CRITICAL on Ubuntu 8.04

    I was wondering why whenever I use the GTK Look and Feel, my JComboBox's cause GTK issues. They also don't display right...
    Here is the code I am using....
    import javax.swing.*;
    public class ComboBoxDisplayTest extends JFrame
      public ComboBoxDisplayTest()
        try
          UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
          SwingUtilities.updateComponentTreeUI(this);
        catch(Exception ex)
          ex.printStackTrace();
        JComboBox cb = new JComboBox();
        this.add(cb);
        cb.addItem("Item 1");
        cb.addItem("Item 2");
      public static void main(String[] args)
        ComboBoxDisplayTest c = new ComboBoxDisplayTest();
        c.pack();
        c.setVisible(true);
    }This is what get's printed onto the terminal when I run the program:
    java ComboBoxDisplayTest
    (<unknown>:7078): Gtk-WARNING **: Attempting to add a widget with type GtkButton to a GtkComboBoxEntry (need an instance of GtkEntry or of a subclass)
    (<unknown>:7078): Gtk-CRITICAL **: gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failedWhat exactly is going on?
    Is there something wrong with my code?
    Is there any way to fix this?
    Any answers are much appreciated...
    Thanks

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6624717
    as far as i know (i am using Ubuntu 7.10 & OpenJDK 1.6.0_0-b11 & Sun JDK) not fixed yet ....
    Ronald

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

  • I am having horrible problems getting some examples to work

    I am trying to get a couple examples to work from out of Java Examples in a Nutshell, but they are programmed oddly and will not work. I am using a windows 2000 platform with JDK 1.3.1 installed and working properly.
    I have so far typed in these 2 examples:
    import javax.swing.*;
    import java.awt.*;
    public class Containers extends JPanel
    { public Containers()
    { this.setBackground(Color.white);
    this.setFont(new Font("Dialog", Font.BOLD,24));
    JPanel p1 = new JPanel();
    p1.setBackground(new Color(200, 200, 200)); // Panel1 is darker
    this.add(p1); //p1 is contained by this component
    p1.add(new JButton("#1")); //Button 1 is contained in p1
    JPanel p2 = new JPanel();
    p2.setBackground(new Color(150,150,150)); // p2 is darker than p1
    p1.add(p2); // p2 is contained in p1
    p2.add(new JButton("#2")); // button 2 is contained in p2
    JPanel p3 = new JPanel();
    p3.setBackground(new Color(100,100,100));
    p2.add(p3); // p3 is contained in p2
    p3.add(new JButton("#3")); // button 3 is contained in p3
    JPanel p4 = new JPanel();
    p4.setBackground(new Color(150,150,150));
    p1.add(p4);
    p4.add(new JButton("#4")); //button 4 is contained in p4
    p4.add(new JButton("#5")); //Button 5 is also contained in p4
    this.add(new JButton("#6")); // button 6 is contained in this component
    And this program
    //ShowComponent.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.beans.*;
    import java.lang.reflect.*;
    import java.util.Vector;
    public class ShowComponent extends JPanel
    public static void main(String[] args)
    {  // process the command line to get the compenents to display
    Vector components = getComponentsFromArgs(args);
    // Create a frame (Window) to display the components to display
    JFrame frame = new JFrame("ShowComponent");
    // Handle window close requests by exiting the VM
    frame.addWindowListener(new WindowAdapter() { //anonymous inner class
    public void WindowClosing(WindowEvent e) { System.exit(0); }
    // set up a menu system that allows the user to select the Look And Feel
    // of the component from a list of installed PLAF's
    JMenuBar menubar = new JMenuBar(); // create a menu bar
    frame.setJMenuBar(menubar); // tell the frame to display the menubar
    JMenu plafmenu = createPlafMenu(frame); // create a menu
    menubar.add(plafmenu); // Add the menu to the menubar
    // Create a JTabbedPane to display each of the components
    JTabbedPane pane = new JTabbedPane();
    // Now add each component as a tab of the tabbed pane
    // use the unqualified component classname as the tab text
    for(int i = 0; i < components.size(); i++)
    { Component c = (Component)components.elementAt(i);
    String classname = c.getClass().getName();
    String tabname = classname.substring(classname.lastIndexOf('.')+1);
    pane.addTab(tabname,c);
    // Add the tabbedpane to the frame. Note: the call to getContentPane()
    // This is required for JFrame, but not for most swing components
    frame.getContentPane().add(pane);
    // Set the frame size and pop it up
    frame.pack(); //Make the frame as big as its children need
    frame.setVisible(true); // Make the frame visible on the screen
    // The main() method exits now but the Java VM keeps running because
    // all AWT programs automatically start an event-handling thread.
    //** this static method queries the system to find out what **
    //** Pluggable LookAndFeel (PLAF) implementations are available **
    //** then it creates a JMenu component that lists each of the **
    //** implementations by name and allows the user to select one **
    //** of them using JRadioButtonMenuItem components. When the **
    //** user selects one, the selected menu item traverses the **
    //** component hierarchy and tells all components to use the new**
    //** PLAF. **
    public static JMenu createPlafMenu(final JFrame frame)
    { //Creates the menu
    JMenu plafmenu = new JMenu("Look and Feel");
    // Create an object used for radio button mutual exclusion
    ButtonGroup radiogroup = new ButtonGroup();
    //Look up the available look and feels
    UIManager.LookAndFeelInfo[] plafs = UIManager.getInstalledLookAndFeels();
    //Loop through the plafs, add a menu item for each one
    for(int i = 0; i < plafs.length; i++)
    { String plafName = plafs[i].getName();
    final String plafClassName = plafs.getClassName();
    // Create the menu items
    JMenuItem item = plafmenu.add(new JRadioButtonMenuItem(plafName));
    // tell the menu item what to do when it is selected
    item.addActionListener(new ActionListener()
    { public void actionPerformed(ActionEvent e)
    { try
    { // Set the new Look And Feel
    UIManager.setLookAndFeel(plafClassName);
    // tell each component to change its look and feel
    SwingUtilities.updateComponentTreeUI(frame);
    //tell the frame to resize itsself to its childrens
    // new desired services
    frame.pack();
    catch(Exception ex) {System.err.println(ex);
    // Only allow one menu item to be selected at once
    radiogroup.add(item);
    return plafmenu;
    //** this method loops through the command line arguements looking for **
    //** class names of components to create and property settings for those**
    //** components in the form name=value. this method demonstrates **
    //** reflection and JavaBeans introspection as they can be aplied to **
    //** dynamically created GUI's **
    public static Vector getComponentsFromArgs(String[] args)
    { Vector components = new Vector();  // List of Components to return
    Component component = null; // the current component
    PropertyDescriptor[] properties = null; // Properties of the component
    Object[] methodArgs = new Object[1]; // we'll use this below
    nextarg: // this is a labeled loop
    for (int i = 0; i < args.length; i++)
    { // loop through all the arguments
    // if the argument does not contain an equal sign, then
    // it is a component class name. Otherwise it is a
    // property setting
    int equalsPos = args[i].indexOf('=');
    if (equalsPos == -1)
    { // Its the name of a component
    try { //Load the named component class
    Class componentClass = Class.forName(args[i]);
    //Instantiate it to create the component instance
    component = ((Component)componentClass.newInstance());
    //Use Java beans to introspect the component
    //And get the list of properties it supports
    BeanInfo componentBeanInfo = Introspector.getBeanInfo(componentClass);
    properties = componentBeanInfo.getPropertyDescriptors();
    catch (Exception e)
    { // If an step failed, print an error and exit
    System.out.println("Can't load, instantiate, " +
    "or introspect: " +args[i]);
    System.exit(1);
    //If we succeeded, store the component in the vector
    components.addElement(component);
    else { // the arg is a name=value property specification
    String name = args[i].substring(0, equalsPos); //property name
    String value = args[i].substring(equalsPos+1); //property value
    // If we do not hava component to set this proerty on, skip!
    if (component == null) continue nextarg;
    // Now look through the properties descriptors for this
    // Component to find one with the same name
    for(int p = 0; p < properties.length; p++)
    { if (properties[p].getName().equals(name))
    { // okay, we found a property of the right name
    // now to get its type, and the setter method
    Class type = properties[p].getPropertyType();
    Method setter = properties[p].getWriteMethod();
    //check if property is read- only !
    if (setter == null)
    { System.err.println("Property " + name+ "is read-only");
    continue nextarg; // continue with the next arguement
    // try to convert the property value to the right type
    // we support a small set of common property types here
    // Store the converted value in an object[] so it can
    //be easily passed when we invoke the property setter
    try { if (type == String.class)
    { // no conversion needed
    methodArgs[0] = value;
    else if (type == int.class)
    { // String to int
    methodArgs[0] = Integer.valueOf(value);
    else if (type == boolean.class)
    { //to boolean
    methodArgs[0] = Boolean.valueOf(value);
    else if (type == Color.class)
    { // to Color
    methodArgs[0] = Color.decode(value);
    else if (type == Font.class)
    { // String to Font
    methodArgs[0] = Font.decode(value);
    else { // if we cannotconvert, ignore the proprty
    System.err.println("Property " + name+ " is of unsupported type "
    + type.getName());
    continue nextarg;
    catch (Exception e)
    { System.err.println("Can't set Property: " + name);
    // NOw go to next command-line arg
    continue nextarg;
    // If we get here we didn't find the named property
    System.err.println("Warning: No such property: " + name);
    return components;
    //** A component subclass that demonstrates nested containers and components.
    //** It creates the hierarchy shown below, and uses different colors to
    //** distinguish the different nesting levels of the containers
    //** containers---panel1----button1
    //** | |---panel2----button2
    //** | | |----panel3----button3
    //** | |------panel40---button4
    //** | |---button5
    //** |---button6
    They both compile fine but when I go to run them together I get an error. the command given in the book to run them both together is:
    java ShowComponent\Containers
    But it does not work. I also tried to append Containers to the bottom of ShowComponent and I got an error that said public class Containers extends JPanel needs to have its own file called Containers.java . . I do not understand that as the file was named correctly for ShowComponent.java. I need to knw either what the true command is for running the programs together or what to name container.java that will make it run inside of ShowContainer.java
    this is very frustrating as I need to know these answers for work and no one here in the IT department knows how to program in Java but me

    Hi,
    I tried the example and got some weird error messages as follows:
    ********* error messages*********
    ShowComponent.java:90: cannot resolve symbol
    symbol : method getName ()
    location: class javax.swing.UIManager.LookAndFeelInfo[]
    { String plafName = plafs.getName();
    ^
    ShowComponent.java:91: cannot resolve symbol
    symbol : method getClassName ()
    location: class javax.swing.UIManager.LookAndFeelInfo[]
    final String plafClassName = plafs.getClassName();
    ^
    ShowComponent.java:139: cannot resolve symbol
    symbol : method indexOf (char)
    location: class java.lang.String[]
    int equalsPos = args.indexOf('=');
    ^
    ShowComponent.java:143: cannot resolve symbol
    symbol : method forName (java.lang.String[])
    location: class java.lang.Class
    Class componentClass = Class.forName(args);
    ^
    ShowComponent.java:161: cannot resolve symbol
    symbol : method substring (int,int)
    location: class java.lang.String[]
    String name = args.substring(0, equalsPos); //property name
    ^
    ShowComponent.java:162: cannot resolve symbol
    symbol : method substring (int)
    location: class java.lang.String[]
    String value = args.substring(equalsPos+1); //property value
    ^
    6 errors.
    *****end of error messages*****
    I use jdk1.3 and Win2000. Can anybody tell me how to delete above error messages?
    Thanks a lot.
    Li

  • Check java on users PC and give message

    The following code has been written with Java 1.4 and works great, but if a user has Java 1.3 they get an error message and if a user has Java 1.2 nothing happens at all. Is there a way to check if the user is using a version older than 1.4 and if so pop up a message telling them they need to download a newer version of Java?
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.util.List;
    import java.io.*;
    import java.util.*;
    import javax.xml.parsers.*;
    import javax.xml.transform.*;
    import javax.xml.transform.dom.*;
    import javax.xml.transform.stream.*;
    import org.w3c.dom.*;
    public class Sametime extends JFrame implements ActionListener {
        private int indentation = -1;
        JPanel panel = new JPanel();
        JTextArea jta = new JTextArea(
        //Instructions for user
        "For a successful buddy list migration do the following:\n"
        + "1. Save your current Sametime Buddy List to your PC.\n   "
        + "The default location should be: C:/Program Files/Lotus/Sametime Client.\n"
        + "  A. Open the Sametime Client.\n"
        + "  B. Click on People\n"
        + "  C. Click on Save List.\n"
        + "  D. Save as your first.last.dat\n"
        + "     Ex. john.doe.dat\n"
        + "NOTE: If you have AOL contacts in your Sametime buddy list they will not be migrated.\n");
        JButton browse = new JButton("Continue");
        JButton exit = new JButton("Exit");
        public Sametime() {
            super("Sametime Buddy List Migration");
            setSize(610, 245);
            Container c = this.getContentPane();
            c.add(panel);
            browse.addActionListener(this);
            exit.addActionListener(this);
            panel.add(jta);
            panel.add(browse);
            panel.add(exit);
            jta.setEditable(false);
            setLookAndFeel();
            setVisible(true);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        } //end Sametime
        public class DATFilter extends javax.swing.filechooser.FileFilter {
            public boolean accept(File f) {
                //if it is a directory -- we want to show it so return true.
                if (f.isDirectory())
                    return true;
                String extension = getExtension(f);//get the extension of the file
                //check to see if the extension is equal to "dat"
                if ((extension.equals("dat")))
                    return true;
                //default -- fall through. False is return on all
                //occasions except:
                //a) the file is a directory
                //b) the file's extension is what we are looking for.
                return false;
            }//end accept
            public String getDescription() {
                return "dat files";
            }//end getDescription
             * Method to get the extension of the file, in lowercase
            private String getExtension(File f) {
                String s = f.getName();
                int i = s.lastIndexOf('.');
                if (i > 0 &&  i < s.length() - 1)
                    return s.substring(i+1).toLowerCase();
                return "";
            }//end getExtension
        }//end class DATFilter
        public void actionPerformed(ActionEvent e) {
            //Default Location for JFileChooser search
            String error = "The file selected is not a .dat file!\n"
            + "Please select your recently saved .dat file and try again.";
            JFileChooser fc = new JFileChooser("/Program Files/Lotus/Sametime Client");
            fc.setFileFilter(new DATFilter());
            fc.setFileSelectionMode( JFileChooser.FILES_ONLY);
            String user = System.getProperty("user.name");// finds who the current user is
            if (e.getSource() == browse) {
                int returnVal = fc.showSaveDialog(Sametime.this);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    //if (fc.getSelectedFile().getName().equals(".dat")){
                    if (fc.getSelectedFile().getName().endsWith(".dat")){ // checks to see if selected file is .dat
                    }else{
                        JOptionPane.showMessageDialog(null, error, "Wrong File", JOptionPane.ERROR_MESSAGE);
                        return;
                    }//end else
                    try {
                        String[] contactArray = parseDatFile(fc.getSelectedFile());
                        Document document = createXMLDocument(contactArray);
                        saveToXMLFile(
                        document,
                        new File(
                        "C:/Documents and Settings/" + user +"/My Documents/OLCS/",// looks for directory for list
                        "contacts-list_migration.ctt"));
                    } catch (Exception exc) {
                        File f = new File("C:/Documents and Settings/" + user +"/My Documents/OLCS/");// setting directory for list if not there
                        boolean yes = true;
                        yes = f.mkdir();// creating directory
                        try {
                            String[] contactArray = parseDatFile(fc.getSelectedFile());
                            Document document = createXMLDocument(contactArray);
                            saveToXMLFile(
                            document,
                            new File(
                            "C:/Documents and Settings/" + user +"/My Documents/OLCS/",// used only if the directory didn't exist
                            "contacts-list_migration.ctt"));
                            //exc.printStackTrace();// not sure if this is needed?
                        } catch (Exception exc1) {
                            exc1.printStackTrace();
                        }//end inner catch
                    }// end catch
                }// end if
                if(returnVal==JFileChooser.CANCEL_OPTION){
                    String Warning = "You did not migrate your Sametime buddy list at this time.";
                    JOptionPane.showMessageDialog(null, Warning, "Migration Canceled", JOptionPane.WARNING_MESSAGE);
                    return;
                }else{
                    String thankyou = "Thank You for Migrating your Sametime buddy list to OLCS"
                    + "\nYour new OLCS buddy list has been saved to:"
                    + "\nC:/Documents and Settings/" + user +"/My Documents/OLCS"
                    + "\n as: Contact-List_migration.ctt"
                    + "\n\n To be able to use Contact-List_migration.ctt for Windows Messenger:"
                    + "\n1. Log into Windows Messenger."
                    + "\n2. Click on File"
                    + "\n3. Click on 'Import Contacts from a Saved File...'"
                    + "\n4. Open OLCS in My Documents"
                    + "\n5. Click on 'Contact-list_migration.ctt'"
                    + "\n6. Click Open to import the list."
                    + "\n   A window will pop up confirming that you want to add all of the contacts"
                    + "\n   Click 'yes'"
                    + "\n   Your buddy list is ready to be used.";
                    JOptionPane.showMessageDialog(null, thankyou, "Migration Completed", JOptionPane.INFORMATION_MESSAGE);//Change this when defualt directory is known.
                }//end if else statement
            } //end if
            System.exit( 0 );
            if (e.getSource() == exit) {
                System.exit( 0 );
            } //end if
        } //end actionPerformed
        String[] parseDatFile(File datFile)
        throws Exception    {
            List list = new ArrayList();
            BufferedReader br = new BufferedReader(new FileReader(datFile));
            String line;
            while ((line = br.readLine()) != null) {
                line = line.trim();
                if (line.indexOf("U") != 0)
                    continue;
                int p = line.indexOf("::");
                if (p == -1)
                    continue;
                line = line.substring(p + 2).trim();
                if (line.indexOf("AOL") == 0)
                    continue;
                p = line.indexOf(",");
                if (p != -1)
                    line = line.substring(0, p);
                line = line.trim() + "@mci.com";
                if (list.indexOf(line) == -1)
                    list.add(line);
            }//end while
            br.close();
            String[] contactArray = new String[list.size()];
            list.toArray(contactArray);
            return contactArray;
        }// end String
        // setting up the XML file
        Document createXMLDocument(String[] contactArray) throws Exception {
            DocumentBuilderFactory dBF = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = dBF.newDocumentBuilder();
            DOMImplementation domImpl = builder.getDOMImplementation();
            Document document = domImpl.createDocument(null, "messenger", null);
            Element root = document.getDocumentElement();
            Element svcElm = document.createElement("service");
            Element clElm = document.createElement("contactlist");
            svcElm.setAttribute("name", "Microsoft RTC Instant Messaging");
            svcElm.appendChild(clElm);
            root.appendChild(svcElm);
            for (int i = 0; i < contactArray.length; i++) {
                Element conElm = document.createElement("contact");
                Text conTxt = document.createTextNode(contactArray);
    conElm.appendChild(conTxt);
    clElm.appendChild(conElm);
    }//end for
    return document;
    }// end Document
    void saveToXMLFile(Document document, File xmlFile) throws Exception {
    OutputStream os =
    new BufferedOutputStream(new FileOutputStream(xmlFile));
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");//puts information on seperate lines
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");//gives the XML file indentation
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
    DOMSource source = new DOMSource(document);
    StreamResult result = new StreamResult(os);
    transformer.transform(source, result);
    os.close();
    }//end saveToXMLFile
    public static void main(String[] args) {
    Sametime st = new Sametime();
    ImageIcon picIcon = new ImageIcon(st.getClass().getResource("/ST_Migration/images/mci.gif"));//Change when default is known!
    st.setIconImage(picIcon.getImage());
    } //end main
    private void setLookAndFeel() {
    try {
    UIManager.setLookAndFeel(
    UIManager.getSystemLookAndFeelClassName());
    SwingUtilities.updateComponentTreeUI(this);
    } catch (Exception e) {
    System.err.println("Could not use Look and Feel: " + e);
    } //end catch
    } //end void setLookAndFeel
    } //end public class Sametime

    Well, if you don't want to use Package.isCompatibleWith and the version numbers will always be of the form x.y where y is at most one digit, you can use Double.parseDouble() and then compare the numbers. Otherwise you need to write a method of your own.

  • 3 questions on visual changes and positioning

    Hello everyone,
    I hope I have the right section for my questions. (so many categories) I have three questions that I hope I can get answered.
    Question 1 ) I am writing an application that uses a JDesktopPane. I have a menu that each choice opens up a JInternalFrame. One of my internal frames contains option settings for the app. One of the option selections is the type of look and feel of the gui. I have three JRadioButtons that chooses the three built in types. When I use the method (see below) to change the gui look, it only effects the Internal Frame, not the rest of the app. Is there a way I can get it to change the rest of the frames and the main JDesktop.
    private UIManager.LookAndFeelInfo looks[];
    public void lookAndFeel()
              looks = UIManager.getInstalledLookAndFeels();
              try
                   UIManager.setLookAndFeel(looks[lookChoice].getClassName());
                   SwingUtilities.updateComponentTreeUI(this);
              catch(Exception exception)
                   try
                        UIManager.setLookAndFeel(looks[0].getClassName());
                   catch(Exception guiException)
                        // Nothing yet...
         }Question 2 ) Positioning --- I understand how to use layout managers, but is there a way I can override the positioning of objects? Sometimes, I want to postion objects to a point. Instead of automatic positioning.
    Question 3 ) Adjusting properties --- I notice that when I create a different font and if I want an object to use that font then I need to setFont() for the object. Unfortunately, I have noticed that this needs to be done for every object. Is there a way to set the font for all the objects in a JPanel or JFrame at once?
    Thanks everyone, (sorry for the numerous questions, just has been building for awhile)
    7

    Question 1 ) I am writing an application that uses a
    JDesktopPane. I have a menu that each choice opens up
    a JInternalFrame. One of my internal frames contains
    option settings for the app. One of the option
    selections is the type of look and feel of the gui. I
    have three JRadioButtons that chooses the three built
    in types. When I use the method (see below) to change
    the gui look, it only effects the Internal Frame, not
    the rest of the app. Is there a way I can get it to
    change the rest of the frames and the main JDesktop.Try doing
    revalidate();
    repaint()
    on all of them
    Question 2 ) Positioning --- I understand how to use
    layout managers, but is there a way I can override the
    positioning of objects? Sometimes, I want to postion
    objects to a point. Instead of automatic positioning.Your choice is either to call setLayout(null) and set component positions yourself or to create/extend your own layout manager
    >
    Question 3 ) Adjusting properties --- I notice that
    when I create a different font and if I want an object
    to use that font then I need to setFont() for the
    object. Unfortunately, I have noticed that this needs
    to be done for every object. Is there a way to set the
    font for all the objects in a JPanel or JFrame at
    once?Not that I can think of. Why not just create one method where you can set everybody's font with a font parameter?
    >
    Thanks everyone, (sorry for the numerous questions,
    just has been building for awhile)
    7

  • Error when trying to use ImageIcon

    Hi,
    I am trying to use an ImageIcon to store an icon for plugins so that they can customize their menu and toolbar entries. I use a generic class, PaletteClass, to design all the plugins, and then extend PaletteClass to create individual plugins.
    PaletteClass:
    public class PaletteClass implements ItemListener{
          * PaletteClass
          * Superclass for the palettes in iKalk
          * @author Nathan Jarus
          * @version 0.1
         JFrame frame = new JFrame();//Window
         GridBagLayout layout = new GridBagLayout();
         GridBagConstraints constraints = new GridBagConstraints();
         JPanel main = new JPanel(layout);
         JToggleButton cmdTop = new JToggleButton("Stick to Top");
         //iKalk interface variables
         static String description = "Unnamed Plugin"; //Name of plugin
         ImageIcon icon = new ImageIcon();  //icon of plugin
         static boolean state = true; //is it visible?
         //static JToggleButton button = new JToggleButton(description, icon, state);
         static JToggleButton button;
         //static JToggleButton button = new JToggleButton(description, state);
         JCheckBoxMenuItem menu = new JCheckBoxMenuItem(description, icon, state);
         //boolean caret = false;//Used in determining when to clear the text box
         //boolean clear = false;
         //double tmp = 0;//Used in calculations
         //char op = ' ';//Used in calculations
         //Constructor
         PaletteClass(iKalk ikalk){
              setIcon("/images/generic.gif",ikalk,this);
              menu.addItemListener(this);
              //button.addItemListener(this);
              frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
              //frame.setLayout(new BorderLayout());
              try {
                   UIManager.setLookAndFeel(iKalk.getLF());
              } catch (UnsupportedLookAndFeelException e) {
                   JOptionPane.showMessageDialog(null,"How on earth did you get this message?  Check for a virus.  /n/nYour JRE has changed in the milliseconds that passed between the original loading of the program and this window loading!", "A message you should not be seeing", JOptionPane.ERROR_MESSAGE);
              constraints.fill = GridBagConstraints.BOTH;
              constraints.anchor = GridBagConstraints.CENTER;
              //Stick to Top button
              cmdTop.addItemListener(this);
              addComp(main, cmdTop, layout, constraints, 0, 0, 1, 1, 0, 100);
              //frame.add(main, BorderLayout.NORTH);
              //frame.setVisible(true);
              init();
              //updateGFX();
              //button = new JToggleButton(description, icon, state);
              //setIcon("/images/generic.gif",ikalk,this);
         public void init(){
              frame.setLayout(new BorderLayout());
              frame.add(main, BorderLayout.NORTH);
         //Item listener
         public void itemStateChanged(ItemEvent ie) {
              if(ie.getSource().equals(cmdTop)){
                   if (frame.isAlwaysOnTop()){
                        frame.setAlwaysOnTop(false);
                   else {
                        frame.setAlwaysOnTop(true);
              else if(ie.getSource().equals(button)){
                   if(button.isSelected()){
                        setVisible(true);
                   else{
                        setVisible(false);
              else if(ie.getSource().equals(menu)){
                   if(menu.isSelected()){
                        setVisible(true);
                   else{
                        setVisible(false);
         //Update the L&F
         public void updateGFX(){
              setVisible(false);
              SwingUtilities.updateComponentTreeUI(frame);
              SwingUtilities.updateComponentTreeUI(main);
              setVisible(true);
         //Decide whether or not the window is onscreen
         public boolean isShowing(){
              return frame.isVisible();
         public void setVisible(boolean v){
              frame.setVisible(v);
              state = isShowing();
         public void setVisible(){
              frame.setVisible(true);
              state = isShowing();
         /*Add a component to the gridbag layout
          *Args:
          *JPanel to                                   the JPanel to add the item to
          *Component what                         what to add
          *GridBagLayout layout                    the layout to add it to
          *GridBagConstraints constraints     the constraints to modify
          *int row                                   the row to add it to
          *int column                              the column to add it to
          *int numRows                              the number of rows the item crosses
          *int numCols                              the number of columns the item crosses
          *int weightX                              the x-weight of the item
          *int weightY                              the y-weight of the item
         public void addComp(JPanel to, Component what, GridBagLayout layout, GridBagConstraints constraints, int row, int column, int numRows, int numCols, int weightX, int weightY){
              //Set the constraint parameters
              constraints.gridx = column;
              constraints.gridy = row;
              constraints.gridwidth = numCols;
              constraints.gridheight = numRows;
              constraints.weightx = weightX;
              constraints.weighty = weightY;
              //Set these constraints in the layout
              layout.setConstraints(what, constraints);
              //Add the component
              to.add(what);
         public void setIcon(String path, iKalk ikalk, PaletteClass parent){
              parent.icon = new ImageIcon(ikalk.getClass().getResource(path));
    }This is one of the classes that I have trouble with:
    NumberPad:
    public class NumberPad extends PaletteClass implements ActionListener{
         //Set up the objects so that I can access them from another method
         public NumberPad(iKalk ikalk){
              super(ikalk);
    //Set the description
              description = "Number Pad";
              //setIcon("/images/NumberPad.gif", ikalk, this);
              button = new JToggleButton(description, icon, state);
    //Set up the frame
              try {
                   UIManager.setLookAndFeel(iKalk.getLF());
              } catch (UnsupportedLookAndFeelException e) {
                   //JOptionPane.showMessageDialog(null,"How on earth did you get this message?  Check for a virus.  /n/nYour JRE has changed in the milliseconds that passed between the original loading of the program and this window loading!", "A message you should not be seeing", JOptionPane.ERROR_MESSAGE);
              frame.setSize(155,160);
              frame.setLocation(500,500);
              frame.setTitle(description);
              updateGFX();
    //Set up the number entry pad
              JPanel panNumbers = new JPanel(new GridLayout(4,3));
              JButton cmd0 = new JButton("0");
              JButton cmd1 = new JButton("1");
              JButton cmd2 = new JButton("2");
              JButton cmd3 = new JButton("3");
              JButton cmd4 = new JButton("4");
              JButton cmd5 = new JButton("5");
              JButton cmd6 = new JButton("6");
              JButton cmd7 = new JButton("7");
              JButton cmd8 = new JButton("8");
              JButton cmd9 = new JButton("9");
              JButton cmdDec = new JButton(".");
              JButton cmdPM = new JButton("+/-");
              cmd0.addActionListener(this);
              cmd1.addActionListener(this);
              cmd2.addActionListener(this);
              cmd3.addActionListener(this);
              cmd4.addActionListener(this);
              cmd5.addActionListener(this);
              cmd6.addActionListener(this);
              cmd7.addActionListener(this);
              cmd8.addActionListener(this);
              cmd9.addActionListener(this);
              cmdDec.addActionListener(this);
              cmdPM.addActionListener(this);
              panNumbers.add(cmd7);
              panNumbers.add(cmd8);
              panNumbers.add(cmd9);
              panNumbers.add(cmd4);
              panNumbers.add(cmd5);
              panNumbers.add(cmd6);
              panNumbers.add(cmd1);
              panNumbers.add(cmd2);
              panNumbers.add(cmd3);
              panNumbers.add(cmd0);
              panNumbers.add(cmdDec);
              panNumbers.add(cmdPM);
              panNumbers.setVisible(true);
    //Final adding and init
              super.addComp(main, panNumbers, layout, constraints, 1, 0, 4, 1, 0, 0);
              //super.setVisible();
              setIcon("/images/NumberPad.gif", ikalk, this);
         public void actionPerformed(ActionEvent ae) {
              if(ae.getActionCommand().equals("1")){
                   Functions.addOne();
              else if(ae.getActionCommand().equals("2")){
                   Functions.addTwo();
              else if(ae.getActionCommand().equals("3")){
                   Functions.addThree();
              else if(ae.getActionCommand().equals("4")){
                   Functions.addFour();
              else if(ae.getActionCommand().equals("5")){
                   Functions.addFive();
              else if(ae.getActionCommand().equals("6")){
                   Functions.addSix();
              else if(ae.getActionCommand().equals("7")){
                   Functions.addSeven();
              else if(ae.getActionCommand().equals("8")){
                   Functions.addEight();
              else if(ae.getActionCommand().equals("9")){
                   Functions.addNine();
              else if(ae.getActionCommand().equals("0")){
                   Functions.addZero();
              else if(ae.getActionCommand().equals(".")){
                   Functions.addDec();
              else if(ae.getActionCommand().equals("+/-")){
                   Functions.PlusMins();
         /*public void init(){
         public void main(String [] args){
    }This is the code I use to load the plugins:
    void addPlugin(PaletteClass plugin){
              //pluginsVector.addElement(plugin);
              //plugin.setVisible();
              //toolMain.add(PaletteClass.button);
              pluginsVector.addElement(plugin);
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        toolMain.add(PaletteClass.button);
         }When I load this code, I get the following error (in Eclipse SDK):
    java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
         at java.lang.reflect.Constructor.newInstance(Unknown Source)
         at iKalk.loadPlugin(iKalk.java:587)
         at iKalk.loadPlugins(iKalk.java:578)
         at iKalk.<init>(iKalk.java:466)
         at iKalk$4.run(iKalk.java:563)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.lang.NullPointerException
         at javax.swing.ImageIcon.<init>(Unknown Source)
         at PaletteClass.setIcon(PaletteClass.java:172)
         at NumberPad.<init>(NumberPad.java:82)
         ... 15 more
    If anyone knows what I am doing wrong, I'd like to know. I've tried several ways to fix it (as you can probably tell from the commented out code), but none of them worked.
    Sorry if my code isn't the cleanest; it's still in development =]
    PS: is it just me or does the code button in the post dialog still not work correctly?
    Thanks,
    LinuxMercedes

    Sorry for all the code. Here's a truncated version:
    PaletteClass:
    public class PaletteClass implements ItemListener{
         JFrame frame = new JFrame();//Window
         GridBagLayout layout = new GridBagLayout();
         GridBagConstraints constraints = new GridBagConstraints();
         JPanel main = new JPanel(layout);
         JToggleButton cmdTop = new JToggleButton("Stick to Top");
         static String description = "Unnamed Plugin"; //Name of plugin
         ImageIcon icon = new ImageIcon();  //icon of plugin
         static boolean state = true; //is it visible?
         static JToggleButton button;
         JCheckBoxMenuItem menu = new JCheckBoxMenuItem(description, icon, state);
         PaletteClass(iKalk ikalk){
              setIcon("/images/generic.gif",ikalk,this);
              init();
         public void init(){
              frame.setLayout(new BorderLayout());
              frame.add(main, BorderLayout.NORTH);
         public void setIcon(String path, iKalk ikalk, PaletteClass parent){
              parent.icon = new ImageIcon(ikalk.getClass().getResource(path));
    }NumberPad:
    public class NumberPad extends PaletteClass implements ActionListener{
         public NumberPad(iKalk ikalk){
              super(ikalk);
    //Set the description
              description = "Number Pad";
              button = new JToggleButton(description, icon, state);
              setIcon("/images/NumberPad.gif", ikalk, this);
    }Code I use to load Plugins:
    void addPlugin(PaletteClass plugin){
              pluginsVector.addElement(plugin);
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        toolMain.add(PaletteClass.button);
    }Oh yeah, and please don't go using this code in your projects without asking =]
    Thanks (and my apologies again),
    LinuxMercedes

  • Problem with setMnemonic after upgrading to 1.4.2

    Hi,
    setMnemonic doesnt seem to work properly for JButtons after upgrading from 1.3.1 to 1.4.1. Hot Key works but underlining doesnt show.
    In our app, we have our own controls which are basically derived from Swing controls. In this case JButton.
    I have tried using both setMnemonic API (char as well as int) but no luck. Look and feel we use is Windows look and feel (W2K). Font is Dialog. One thing I have noticed is that if I donot set the look and feel in my app. It seems to work fine. (Metalic).
    Anybody has any clue on how to fix this issue ?
    Thanks in advance
    Sohan

    Hi,
    Here is a code sample for the above problem.
    import java.awt.*;
    import javax.swing.*;
    public class TestFrame {
              public static void main(String[] args) {
                        JButton button = new JButton();
                        JFrame frame = new JFrame();
                        // Add button to the frame
                        //frame.getContentPane().setLayout(new GridBagLayout());
                        //frame.getContentPane().add(button, new GridBagConstraints(3,2,1,1,1.0,1.0,GridBagConstraints.SOUTHEAST,GridBagConstraints.NONE,new Insets (0,0,0,0),0,0));
                        frame.getContentPane().add(button, BorderLayout.NORTH);
                        // Set initial size
                        int frameWidth = 300;
                        int frameHeight = 300;
                        frame.setSize(frameWidth, frameHeight);
                        button.setText ("Button");
                        button.setMnemonic((int)'o' );
                        button.setMargin(new Insets (0,0,0,0));
                        button.setSize (new Dimension (73,21));
                        button.setFont(new Font ("Dialog", Font.PLAIN, 11));
                   try {
                        UIManager.setLookAndFeel ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                        SwingUtilities.updateComponentTreeUI(frame);
                   catch (Exception e){};
                        // Show the frame
                        frame.pack();
                        frame.setVisible(true);
    Sohan

  • Change the color of seperator in JPopupMenu

    hi all,
    i want to change the color of the seperator in JPopupMenu?
    how to do this?
    pls help...
    -Soni

    try this :
    UIManager.put("Separator.foreground",Color.red);
    SwingUtilities.updateComponentTreeUI(this);

  • LookAndFeel issue reloading an Applet in a Web page

    Hey all,
    I have an Applet that runs on a web page (loaded by servlets and JSP's using Tomcat 3.2.1 and Apache). I created my own LookAndFeel class and have a static function in the applet that sets the LookAndFeel to my new class. Everything works fine when the Applet is first loaded. However, when you exit the applet and then reload it, the custom LookAndFeel is gone and all I get is the default Metal. If I load the applet with appletviewer, I can reload it as much as I want and it always loads my LookAndFeel class.
    The static function is as follows
    /** Static initializer to set the LookAndFeel
    static {
    try {
    UIManager.setLookAndFeel(new MyNewLookAndFeel());
    catch (Exception e) {}
    I do not get any exceptions and like I said, everything works great when loaded with appletviewer.
    I have tried adding the SwingUtilities.updateComponentTreeUI(this); in either the start(), init(), or my own createGUI() function and it still does not work.
    Any ideas? Could this be a problem with the browser caching the applet? I am using IE 5.50.

    I have the same problem
    putting them in static doesn't keep the look and feel
    putting them in the applet constructor does'nt keep it
    putting them in init() doesn't keep it
    putting them in start() doesn't keep it
    heck, even putting them in all 4 of them together doesn't keep the look and feel, it always reverts back to metal

Maybe you are looking for

  • AirPlay, iPhone 4 and TV Shows

    Ok, I finally updated to 4.3. My main interest is in an updated AirPlay. I'm glad I can FINALLY AirPlay videos I shot with the iPhone 4 to my apple tv! Issues I've noted: The new iPod "sharing" does not see any tv shows I've added unless they were pu

  • How to add custom sql operations in Database adapters?

    I have a database adapter in ESB configured with insert, update and select operations. I wanted to add another select operation with pure sql. When I added the operation it gave me error "Start of the root element expected" while registering the serv

  • Re-install photoshop CS4 problems... HELP!!

    I have just had to un install photoshop CS4 due to it kept crashing, when I insert the disc to re install nothing happens.... Is there somewhere I can download it and enter my serial number that way? I use photoshop everyday for my job and am panicki

  • Actions for PSE3 (imac G5 Tiger vs. 10.4.1)

    I'm trying to load a Photoshop Action into PSE3. The insructions I'm reading from I believe were written by Barbara Brundage. However I don't understand the following instructions: "Make a copy of this file, open the copy in Photoshop after you've wr

  • Win7 64bit boot camp install Monitor inf

    Does anyone know where I can find a monitor info file to fix the generic monitor issue in win7 on the new 27" imacs?