473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

JPanel like JDialog

19
Hello, in this code suppose that the dlg is defined in one case as a JDialog, I run it and it seems that the JDialog is executed AFTER closing it, so the message is printed after closing the JDialog.
But when I run the code with dlg defined as JPanel it prints the message before I close the JPanel.

Expand|Select|Wrap|Line Numbers
  1. jmnuTest.addActionListener(
  2.          new ActionListener()
  3.          {
  4.             public void actionPerformed(ActionEvent e)
  5.             {
  6.                jmnuTest_actionPerformed(e);
  7.             }
  8.          });

Expand|Select|Wrap|Line Numbers
  1. private void jmnuTest_actionPerformed(ActionEvent e)
  2.    {
  3.       Testwhen dlg = new Testwhen(this);
  4.      System.out.println("I'm here");
  5.  
  6.    }


And I need the JPanel to behave like the JDialog in that sense.. how could I deal with this?
Thanks in advance
Aug 30 '07 #1
9 10956
Nepomuk
3,112 Expert 2GB
Hello, in this code suppose that the dlg is defined in one case as a JDialog, I run it and it seems that the JDialog is executed AFTER closing it, so the message is printed after closing the JDialog.
But when I run the code with dlg defined as JPanel it prints the message before I close the JPanel.

Expand|Select|Wrap|Line Numbers
  1. jmnuTest.addActionListener(
  2.          new ActionListener()
  3.          {
  4.             public void actionPerformed(ActionEvent e)
  5.             {
  6.                jmnuTest_actionPerformed(e);
  7.             }
  8.          });

Expand|Select|Wrap|Line Numbers
  1. private void jmnuTest_actionPerformed(ActionEvent e)
  2.    {
  3.       Testwhen dlg = new Testwhen(this);
  4.      System.out.println("I'm here");
  5.  
  6.    }


And I need the JPanel to behave like the JDialog in that sense.. how could I deal with this?
Thanks in advance
Is your JDialog modal? If so, that would explain the behavior. It will not continue doing anything as long as the JDialog is visible - you will have to switch it to nonmodal.
Expand|Select|Wrap|Line Numbers
  1. dlg.setModal(false);
Aug 30 '07 #2
aleplgr
19
Thanks, then as I understand I need the JPanel to be modal, the JDialog is modal and that's why it shows the message after closing it. The JPanel is not modal and that's why it does not wait until I close it to print the message.
So as I understand I should have to make the JPanel modal, but dlg.setModal(true) is not defined when dlg is a JPanel...
Aug 30 '07 #3
Nepomuk
3,112 Expert 2GB
Thanks, then as I understand I need the JPanel to be modal, the JDialog is modal and that's why it shows the message after closing it. The JPanel is not modal and that's why it does not wait until I close it to print the message.
So as I understand I should have to make the JPanel modal, but dlg.setModal(true) is not defined when dlg is a JPanel...
No, you misunderstood.
JPanels can't be modal. Modal means, that it is in the foreground and nothing else can be accessed. If you want the JDialog to act like the JPanel, you have to switch the JDialog to nonmodal. If you want a JPanel to act like it was modal, you'll have to write that yourself.
Aug 30 '07 #4
JosAH
11,448 Expert 8TB
Note that since Java 1.5. (or 1.6, I don't remember) there are more levels of
modality to pick from than just (non)modal; check the JDialog API documenation
for the details.

kind regards,

Jos
Aug 30 '07 #5
aleplgr
19
But the JPanel prints the message "I'm here" before closing it
and the JDialog prints the message after closing it.
I need the JPanel to print the message after closing it, how could I do that?
Aug 30 '07 #6
JosAH
11,448 Expert 8TB
But the JPanel prints the message "I'm here" before closing it
and the JDialog prints the message after closing it.
I need the JPanel to print the message after closing it, how could I do that?
How do you 'close' a JPanel? Al you can do with it is remove it from its container,
but that's about it. If you want some modality in your application, i.e. a use is
only allowed to work with a particular piece of your appliation, use a modal dialog.
A JDialog is a top level container (like a window) while a JPanel is just part of
another (possibly top level) container.

kind regards,

Jos
Aug 30 '07 #7
Nepomuk
3,112 Expert 2GB
But the JPanel prints the message "I'm here" before closing it
and the JDialog prints the message after closing it.
I need the JPanel to print the message after closing it, how could I do that?
In that case, you should add a listener to the JPanel which is activated, when the Panel is closed (e.g. made invisible). You could have a while-loop, which stops the program from doing anything else until it gets some kind of message from the listener.
Aug 31 '07 #8
aleplgr
19
I've been thinking the first solution: to define it as a JDialog.
And now it works fine, but I need to add everything else (buttons, labels, functionality) from the JPanel to the JDialog.
I tried the setContentPane to "copy" everything from the JPanel to the JDialog but it's not working...It shows the JDialog as if I had done nothing...

Expand|Select|Wrap|Line Numbers
  1. private JPanel contentPane;
  2.  
  3. dlg = new MyDialog(this);
  4. pnl =  new MyPanel (this);
  5. dlg.setContentPane(pnl);
  6. contentPane.add(dlg,  BorderLayout.CENTER);
Aug 31 '07 #9
JosAH
11,448 Expert 8TB
I've been thinking the first solution: to define it as a JDialog.
And now it works fine, but I need to add everything else (buttons, labels, functionality) from the JPanel to the JDialog.
I tried the setContentPane to "copy" everything from the JPanel to the JDialog but it's not working...It shows the JDialog as if I had done nothing...

Expand|Select|Wrap|Line Numbers
  1. private JPanel contentPane;
  2.  
  3. dlg = new MyDialog(this);
  4. pnl =  new MyPanel (this);
  5. dlg.setContentPane(pnl);
  6. contentPane.add(dlg,  BorderLayout.CENTER);
It doesn't work like that; forget about that JPanel and add all the components to
the content pane of the JDialog instead. Don't be afraid to throw away incorrect
code and don't try to hack it a bit more; change it so that everything is correct.

kind regards,

Jos
Aug 31 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Moth | last post by:
I have a PlotPanel class that extends JPanel which I have used previously to display charts in swing guis. I now want to display a graph in a jsp page so I was going to generate the graph and then...
2
by: Seanus | last post by:
Hi all, I've got a little problem with the JDialogs. Housekeeping: I'm on windows xp, with the latest JRE, I'm getting no error as such. Basically, I've got some JDialogs in my program (are...
1
by: dishal | last post by:
Hi, Im having a problem with typing on the JPanel. The thing is, that it works perfectly fine when this line " content.add(jp, BorderLayout.NORTH); " is taken out (its the buttons panel) but when its...
3
by: sezanawa | last post by:
Hi Guys, I have a small application which i wrote in Java. There is a MainFrame extends jfram class. There is another class named LoginDialog extends JDialog. My MainFrame class have main...
5
by: James Barrett | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi all, I am experimenting with JApplet and JPanel. My JApplet contains a JPanel called jpanel1 size 210x210. I created a class myPanel which...
1
by: rpm27 | last post by:
I'm new to Java. I am starting to understand Java GUI dimension (the swing library), and I need someone to clarify something to me: As far as I know, JFrame objects provide a window (with the...
8
by: eddiewould | last post by:
Hi, I want to write a custom widget which will act similarly to a JPanel (i.e it can contain other Components), but semantically it's not a kind of JPanel so it shouldn't extend from it. Here is...
1
by: Akino877 | last post by:
Hello, I have a question regarding Java and Swing programming I wonder if I could ask the forum for some help. I have a JPanel that has a couple of radio buttons and an "OK/Next" button on it. ...
1
by: sibusiso | last post by:
HI Can anyone help with the scenario where where you have to pass a certain data from one JFrame to another. For example, suppose you have a JFrame is your main window you disabled your Jmenu...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.