Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / June 2005

Tip: Looking for answers? Try searching our database.

JDialog not appearing for JWindow under Java 1.5

Thread view: 
Jim Gibson - 10 Jun 2005 00:32 GMT
I recently upgraded from Java 1.4.2 to 1.5.0_03 on a Red Hat 9 system.
When I compiled and tested an existing program that worked fine under
1.4.2 I discovered one small but significant problem.

I am using a JWindow for the main window of an application for its
clean look, because I am emulating a radar screen. Since I can't use of
a menu bar, I use a pop-up menu on a right-mouse-click to configure the
application. One of the menu selections is supposed to show a JDialog
to perform various configuration functions. If the program compiles and
runs under 1.5 the JDialog fails to appear (nothing at all seems to
happen).

If I compile and run the same program under 1.4.2, it works fine, and
the dialog appears. If I change the JWindow to a JFrame, the dialog
appears under either 1.4.2 or 1.5.

Is there some problem with this feature under 1.5? I am doing something
stupid that is causing the dialog not to appear under 1.5 (but somehow
slips through under 1.4.2?)

Here is a sample program. It uses buttons to show the dialog instead of
a pop-up menu, but the effect is the same: under 1.4.2 the dialog
appears; under 1.5 it does not. If the JWindow is changed to JFrame,
the dialog appears in either case:

// DialogTest

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

//public class DialogTest extends JFrame    // works under 1.4.2 or 1.5
public class DialogTest extends JWindow     // works only under 1.4.2
{
 JDialog dialog;

 DialogTest()
 {
   // create main window
   JPanel buttons = new JPanel();
   JPanel content = (JPanel)getContentPane();
   content.setBackground(Color.white);
   content.setPreferredSize(new Dimension(400,400));
   JButton help = new JButton("Help");
   help.addActionListener( new ActionListener() {
     public void actionPerformed( ActionEvent e )
       { show_dialog(true); }});
   JButton quit = new JButton("Quit");
   quit.addActionListener( new ActionListener() {
     public void actionPerformed( ActionEvent e )
       { System.exit(0); }});
   buttons.add(help);
   buttons.add(quit);
   JLabel text = new JLabel("Application",JLabel.CENTER);
   text.setPreferredSize(new Dimension(300,300));
   content.add(text,BorderLayout.CENTER);
   content.add(buttons,BorderLayout.SOUTH);

   // create help dialog
   dialog = new JDialog();
   Container dcon = dialog.getContentPane();
   dialog.setTitle("Dialog Test Help");
   JButton close = new JButton("Close");
   close.addActionListener( new ActionListener() {
     public void actionPerformed( ActionEvent e ) {
       show_dialog(false); }
   });
   JLabel htext = new JLabel("Help text.",JLabel.CENTER);
   htext.setPreferredSize(new Dimension(200,100));
   dcon.add(close,BorderLayout.SOUTH);
   dcon.add(htext);
   dialog.pack();

   pack();
 }

 public void show_dialog( boolean b ) { dialog.setVisible(b); }

 public static void main( String[] args )
 {
   DialogTest dt = new DialogTest();
   dt.setVisible(true);
 }
}

Thanks for any assistance or enlightenment. I am going to go back to
1.4.2 for now, but would like to re-migrate to 1.5 in the future.
Aidan - 10 Jun 2005 00:51 GMT
Your sample app works fine for me using 1.5.0_03. The dialog appears
when I press 'Help'.
Lee Weiner - 10 Jun 2005 01:28 GMT
>I recently upgraded from Java 1.4.2 to 1.5.0_03 on a Red Hat 9 system.
>When I compiled and tested an existing program that worked fine under
[quoted text clipped - 11 lines]
>the dialog appears. If I change the JWindow to a JFrame, the dialog
>appears under either 1.4.2 or 1.5.

<code snipped>

Your code works perfectly for me under 1.5.0_01 under Windows.  So it's more
than a 1.5.0 thing.  It's a 1.5.0 + Linux thing.

Lee Weiner
lee AT leeweiner DOT org
Knute Johnson - 10 Jun 2005 04:14 GMT
> I recently upgraded from Java 1.4.2 to 1.5.0_03 on a Red Hat 9 system.
> When I compiled and tested an existing program that worked fine under
[quoted text clipped - 20 lines]
> appears; under 1.5 it does not. If the JWindow is changed to JFrame,
> the dialog appears in either case:

Jim:

It works just fine for me under XP and 1.5.0_03.  Under FC3 Linux and
1.5.0_03 it works but the dialog is behind your JWindow.  A couple of
points, you should not use JWindow as your primary container but use an
unDecorated JFrame.  Second your JDialog doesn't have an owner which is
why it is probably hiding behind your JWindow.  I rewrote (not as
detailed as yours) your class and it works fine.  Your class was a
little 'scattered' for my taste but that is personal preference.  I've
been programming too long and always try to make my code linear.
Probably not the best thing for event driven code but what can you do.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class DialogTest2 {
    public DialogTest2() {
        JFrame frame = new JFrame();
        frame.setUndecorated(true);
        frame.setPreferredSize(new Dimension(320,240));

        Container cp = frame.getContentPane();

        final JDialog d = new JDialog(frame,"help",true);
        d.setPreferredSize(new Dimension(200,100));
        d.pack();
        d.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
                d.setVisible(false);
            }
        });
   
        JPanel buttons = new JPanel();
        JButton help = new JButton("Help");
        help.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                d.setVisible(true);
            }
        });
        buttons.add(help);
        JButton close = new JButton("Close");
        close.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                System.exit(0);
            }
        });
        buttons.add(close);

        cp.add(buttons,BorderLayout.SOUTH);
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        new DialogTest2();
    }
}

Signature

Knute Johnson
email s/nospam/knute/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.