f



how to check if a certain JFrame exists

Hi!
Another one of those annoying Newbie-questions:

I got a JFrame, which is created by a method invoked by a Button.
Works fine.

Now I want to let the method check if the JFrame is already open, 
because it's not necessary to open it again.

Any way to do this?
I searched java.sun.com and this newsgroup, bu to no avail.
Any help welcomed

0
Daniel
7/20/2003 9:02:02 PM
comp.lang.java.gui 8286 articles. 0 followers. Post Follow

7 Replies
7511 Views

Similar Articles

[PageSpeed] 59

Daniel Moritz <daimeon@web.de> writes:
> I got a JFrame, which is created by a method invoked by a Button.
> Works fine.
> 
> Now I want to let the method check if the JFrame is already open, 
> because it's not necessary to open it again.
> 
> Any way to do this?
> I searched java.sun.com and this newsgroup, bu to no avail.

The place to look for such things is the API documentation.
Window.isShowing(), or Component.isVisible() (both inherited by JFrame)
might be what you want.

/Thomas
0
nobody
7/21/2003 6:39:48 AM
Thomas Weidenfeller wrote:
> Daniel Moritz <daimeon@web.de> writes:
> 
>>I got a JFrame, which is created by a method invoked by a Button.
>>Works fine.
>>
>>Now I want to let the method check if the JFrame is already open, 
>>because it's not necessary to open it again.
>>
>>Any way to do this?
>>I searched java.sun.com and this newsgroup, bu to no avail.
> 
> 
> The place to look for such things is the API documentation.
> Window.isShowing(), or Component.isVisible() (both inherited by JFrame)
> might be what you want.
> 
> /Thomas
OK, thanks

0
Daniel
7/21/2003 7:28:51 AM
Daniel Moritz wrote:
> Thomas Weidenfeller wrote:
> 
>> Daniel Moritz <daimeon@web.de> writes:
>>
>>> I got a JFrame, which is created by a method invoked by a Button.
>>> Works fine.
>>>
>>> Now I want to let the method check if the JFrame is already open, 
>>> because it's not necessary to open it again.
>>>
>>> Any way to do this?
>>> I searched java.sun.com and this newsgroup, bu to no avail.
>>
>>
>>
>> The place to look for such things is the API documentation.
>> Window.isShowing(), or Component.isVisible() (both inherited by JFrame)
>> might be what you want.
>>
>> /Thomas
> 
> OK, thanks
> 
Hmm, it won't work
here's some of my code, maybe it helps:
button.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
         frame = new cardDialog();
         frame.setVisible(true); //necessary as of 1.3
         meinDesktop.add(frame);
         try {
             frame.setSelected(true);
         } catch (java.beans.PropertyVetoException fe) {}
             }
         }
         );
That's the code I use to add a new JFrame (cardDialog) to my 
JDesktopPane. I don't get it where I should look for an existing 
instance of my JFrame

0
Daniel
7/21/2003 11:51:45 AM
Daniel Moritz wrote:
> Hmm, it won't work
> here's some of my code, maybe it helps:
> button.addActionListener(new ActionListener() {
>         public void actionPerformed(ActionEvent e) {
>         frame = new cardDialog();
>         frame.setVisible(true); //necessary as of 1.3
>         meinDesktop.add(frame);
>         try {
>             frame.setSelected(true);
>         } catch (java.beans.PropertyVetoException fe) {}
>             }
>         }
>         );
> That's the code I use to add a new JFrame (cardDialog) to my 
> JDesktopPane. I don't get it where I should look for an existing 
> instance of my JFrame

Make your dialog a private member of the class
and null it in the constructor. Then in the
actionPerformed() method you do something
like this:

   // Create on first access
   if (dialog == null) {
      dialg = new JFrame();
      ... other init stuff ...
   }

   // Show it
   dialog.setVisible (true);



0
Jacob
7/21/2003 12:00:55 PM
Daniel Moritz wrote:
> Hmm, okay, this works fine now, first time I click the button the JFrame 
> shows and all clicks afterwards are ignored.
> But when I close the JFrame (by the little x in the top-right corner) it 
> won't come back again when I click the button

This program does what you're looking for.
Check how yours is different:



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

public class Test implements ActionListener
{
     private JFrame dialog_ = null;

     public void actionPerformed (ActionEvent event)
     {
         if (dialog_ == null)
             dialog_ = new JFrame("TEST");
         dialog_.setVisible (true);
     }

     public static void main (String args[])
     {
         JFrame f = new JFrame();
         f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

         JButton b = new JButton ("Dialog...");
         b.addActionListener (new Test());

         f.getContentPane().add (b);

         f.pack();
         f.setVisible (true);
     }
}




0
Jacob
7/21/2003 2:03:43 PM
Jacob wrote:
> Daniel Moritz wrote:
> 
>> Hmm, okay, this works fine now, first time I click the button the 
>> JFrame shows and all clicks afterwards are ignored.
>> But when I close the JFrame (by the little x in the top-right corner) 
>> it won't come back again when I click the button
> 
> 
> This program does what you're looking for.
> Check how yours is different:
> 
> 
> 
> import javax.swing.*;
> import java.awt.*;
> import java.awt.event.*;
> 
> public class Test implements ActionListener
> {
>     private JFrame dialog_ = null;
> 
>     public void actionPerformed (ActionEvent event)
>     {
>         if (dialog_ == null)
>             dialog_ = new JFrame("TEST");
>         dialog_.setVisible (true);
>     }
> 
>     public static void main (String args[])
>     {
>         JFrame f = new JFrame();
>         f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
> 
>         JButton b = new JButton ("Dialog...");
>         b.addActionListener (new Test());
> 
>         f.getContentPane().add (b);
> 
>         f.pack();
>         f.setVisible (true);
>     }
> }
> 
> 
> 
> 
Jacob wrote:

> Daniel Moritz wrote:
> 
>> Hmm, okay, this works fine now, first time I click the button the 
>> JFrame shows and all clicks afterwards are ignored.
>> But when I close the JFrame (by the little x in the top-right corner) 
>> it won't come back again when I click the button
> 
> 
> This program does what you're looking for.
> Check how yours is different:
> 
> 
> 
> import javax.swing.*;
> import java.awt.*;
> import java.awt.event.*;
> 
> public class Test implements ActionListener
> {
>     private JFrame dialog_ = null;
> 
>     public void actionPerformed (ActionEvent event)
>     {
>         if (dialog_ == null)
>             dialog_ = new JFrame("TEST");
>         dialog_.setVisible (true);
>     }
> 
>     public static void main (String args[])
>     {
>         JFrame f = new JFrame();
>         f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
> 
>         JButton b = new JButton ("Dialog...");
>         b.addActionListener (new Test());
> 
>         f.getContentPane().add (b);
> 
>         f.pack();
>         f.setVisible (true);
>     }
> }
> 
> 
> 
> 
Hmm, still doesn't work.
Does it matter that cardDialog is a JInternalFrame?
Maybe the JInternalFrame 's DefaultCloseOperation doesn't dispose of it 
the way I suppose it would?
Should I alter the JInternalFrames DefaultCloseOperation?

0
Daniel
7/21/2003 2:22:26 PM
"Daniel Moritz" <daimeon@web.de> wrote in message
news:bfgk42$mhb$00$1@news.t-online.com...
> Hmm, it won't work
> here's some of my code, maybe it helps:
> button.addActionListener(new ActionListener() {
>          public void actionPerformed(ActionEvent e) {
>          frame = new cardDialog();
>          frame.setVisible(true); file://necessary as of 1.3
>          meinDesktop.add(frame);
>          try {
>              frame.setSelected(true);
>          } catch (java.beans.PropertyVetoException fe) {}
>              }
>          }
>          );
> That's the code I use to add a new JFrame (cardDialog) to my
> JDesktopPane. I don't get it where I should look for an existing
> instance of my JFrame

JDesktopPane.getAllFrames()


-1
Karol
7/22/2003 1:07:04 PM
Reply:

Similar Artilces:

java.lang.ExceptionInInitializerError: java.lang.ArrayIndexOutOfBoundsException
Hi, I am new to DB2. I am getting this error while loading the DB2Driver. I don't have any idea about where i might have gone wrong. please help me. Below is the stack trace. Stack Trace: java.lang.ExceptionInInitializerError: java.lang.ArrayIndexOutOfBoundsException at COM.ibm.db2.jdbc.app.DB2Driver.SQLAllocEnv(Native Method) at COM.ibm.db2.jdbc.app.DB2Driver.<init>(DB2Driver.java:245) at COM.ibm.db2.jdbc.app.DB2Driver.<clinit>(DB2Driver.java:130) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Cla...

java.lang.StringIndexOutOfBoundsException: String index out of range: 23 at java.lang.String.charAt(String.java:460)
Hi All I am having the torque3.1.jar and postgresql-7.4. I have compiled the new jdbc driver called as postgresql.jar and have placed it in the lib directory from where the ant scripts catch the jars. Whenever i try to access through torque gestList = BaseGestlistPeer.doSelect(new Criteria()); this error arises java.lang.StringIndexOutOfBoundsException: String index out of range: 23 at java.lang.String.charAt(String.java:460) at org.postgresql.jdbc2.ResultSet.toTimestamp(ResultSet.java:1653) at org.postgresql.jdbc2.ResultSet.getTimestamp(ResultSet.java...

java.lang.Set with elements of type java.lang.Set
Roughly I do something along the lines of: Set set = new HashSet(); Set elem = new HashSet(); set.add(elem); // now we change the elem and add it again to the set elem.add(some object here); set.add(elem); I found out the hard way that 'set' may now contain 'elem' either once or twice, the reason being that 'elem.add()' changes the hashCode of elem such that it is not noticed that it is in 'set' already on the 2nd 'set.add()'. Question: What I would actually want is an IdentityHashSet() set = new IdentityHashSet() but this does not...

to use import java.lang.* or import java.lang.Math or none at all?
Hi guys, i knew that by default all java.lang classes will be imported by the compiler during compilation. but, to make it easier for the computer, should i specify which class i really will be using? does this action will boost the performance during compilation and runtime or not a matter at all? the answer to this post will definitely affect my programming style in the future when i'm considering "to import or not to import"... hmm,,, thanks in advance. JPractitioner wrote: > i knew that by default all java.lang classes will be imported by the > compiler during com...

check if a variable in workspace exist from gui
hi, i try to check if a variable EEG in workspace exist: exist(evalin('base','EEG')); but doesn't work how can i try to do?? On 6/28/2014 9:05 AM, Alberto Palumbo wrote: > hi, i try to check if a variable EEG in workspace exist: > exist(evalin('base','EEG')); > > but doesn't work > how can i try to do?? Per doc evalin the expression to evaluate is the second argument of evalin(). Thus you've attempted to use the result of evaluating the variable result for 'EEG' in the base workspace. Try eval...

GUI check existence of handles/variables
Hi everyone, This is GUI related. I need to know on how to check if a handle is available. Here's the scenario: % where x is the variable x = blah blah blah... handles.x = x; guidata(hObject, handles); % if I want to recall this variable x in another function, I would use x = handles.x However, the problem arise when I wanted to check if the variable x was created in the previous function. If I use if exist('handles.x') ..... else .... the function will not be able to recognize 'handles.x' at all. If I am to use if exist('x') ...

Learn about Gui.Lang.Java in series
In this website to learn more about Java and web Combination of Asp. 1. How to connect Java to web { xml,JavaScript}. 2. How to connect Asp to Web {xml,Ado.net,J2ee} The connection and web config is very important to Java and web with using Asp Dot Net. If you want connections more Information below links http://freejavaprogbooks.blogspot.com http://learnaboutweb.blogspot.com http://ganesh-freedotnetbooks1.blogspot.com On Jul 26, 12:22=A0am, Gani <ganeshkumar...@gmail.com> wrote: > In this website ... =2E.. What? ...

Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object
I downloaded jdk-6u7-solaris-sparcv9.tar.Z and installed it by these commands: # zcat jdk-6u7-solaris-sparc.tar.Z | tar -xf - # pkgadd -d . SUNWj6rtx SUNWj6dvx SUNWj6dmx # /usr/jdk/instances/jdk1.6.0/bin/sparcv9/java -version Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object # ls /usr/jdk/instances/ jdk1.5.0 jdk1.6.0 # uname -a SunOS sun1 5.10 Generic sun4u sparc SUNW,Sun-Blade-2500 Please help to fix the error. Thanks. TsanChung wrote: > I downloaded jdk-6u7-solaris-sparcv9.tar.Z and installed it by these > commands: > # zcat jdk-6u7-so...

Error occurred during intialization of VM java/lang/NoClassDefFoundError: java/lang/Object
Good day to all, I have installed the j2se/netbeans binary bundle on red hat 9. I can run everything perfectly as root but when I try to compile with any other user I get: Error occurred during intialization of VM java/lang/NoClassDefFoundError: java/lang/Object When I saw this it seemed like a permissions problem but I checked the permissions and everything seemed fine. All users have execute permissions of javac and java. I have read other threads dealing with the same or similar problem but have not reached any solution yet. I would appreciate if anyone that has run into this type o...

how to check if a uitable already exists in gui?
Hello, does anybody know how to check if a uitable with a specific tag already exists in a gui? ...

CheckBox in Column of JTable: Exception: java.lang.String cannot be cast to java.lang.Boolean
Hello, I have discovered a hidden error. My project was working for awhile, but then I started to get the below error. My error comes from the fact that I'm using a checkbox in a jtable, and I'm using the below "getColumnClass". Thank you, compile: run: Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean at javax.swing.JTable$BooleanRenderer.getTableCellRendererComponent(JTable.java:5412) at javax.swing.JTable.prepareRenderer(JTable.java:5735) at javax.swing.plaf.basic.BasicTableU...

java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
Hi, I'm trying to use the httpclient within Jython (see http://jakarta.apache.org/commons/httpclient/ for more information on the httpclient). My Jython version is: Jython 2.1 on java1.4.2_04 (JIT: null) My Java version is: java version "1.4.2_04" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode) My CLASSPATH includes: jdom.jar xerces.jar jython.jar jt400.jar log4j-1.2.8.jar commons-httpclient-2.0.jar When I just try to perform the import statements from example code I get the error pasted below....

Running existing java-based GUI with matlab
Dear All, I've a java-based GUI (JFEFF: http://feffproject.org/feffproject-feff.html) contains a few parameters that we optimize with matlab using a genetic algorithm. Currently we have to run both of matlab and JFEFF GUI simultaneously, instead of desired run the java-application inside of matlab. This would allow us to reduce significantly the time associated with each optimisation, improve calculations stability, and enables us to use the PCs in conjunction with optimisation. Does anybody has some suggestion in how to do this? All the best Jacinto ...

java program in java GUI
folks I am writing a java GUI that calls other java programs i want to execute java command line options in back ground. I am using java exec command this is part of code Runtime.getRuntime().exec("/root/java/jdk1.5.0_06/bin/java /root/Desktop/project/SAXXMLHandler"); where i want to run SAXXMLHandler java file But i dont get any output thanks CSUIDL PROGRAMMEr wrote: > folks > I am writing a java GUI that calls other java programs > i want to execute java command line options in back ground. I am using > java exec command > this is part of code > >...

general java GUI question : what is latest&greatest java GUI technology to front a mysql applications
(apologies up front if question is too broad or too dumb) I have intermediate java/mysql programming experience and want to take this up a notch and study java+mysql with a view to creating a database application for GUI programming currently I can see books on swing, JSP, JSF ..... its all a bit confusing as each work with JDBC but each are vastly different WRT how they construct a GUI I want to learn a java GUI technology that I can use to sit on top of a mysql database, typical tasks would be -o- form to read data into database (using many html controls -> text boxes, radio buttons, d...

Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object (ant/tomcat/spring)
Hi, I've been trying to get Spring working with ant and tomcat. Ant was building just fine, but I came in today and tried to build it and got this: Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object ?!?! Makes no sense to me. There _is_ an older version of java installed on my machine; but JAVA_HOME and ANT_HOME are set to the correct paths, and <which java>and <java -version> produce the correct version. Any help would greatly alleviate my frustration! Thanks in advance... Courtney ...

Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object (ant/tomcat/spring)
Hi, I've been trying to get Spring working with ant and tomcat. Ant was building just fine, but I came in today and tried to build it and got this: Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object ?!?! Makes no sense to me. There _is_ an older version of java installed on my machine; but JAVA_HOME and ANT_HOME are set to the correct paths, and <which java>and <java -version> produce the correct version. Any help would greatly alleviate my frustration! Thanks in advance... Courtney ...

How to check, if a Java Class exists out of sas data step
Hello, I'm a bit new in SAS and have not as much knowledge about how to invoke java out of saa. To complain to our guidelines, I need to check if the class, I want to use is accessible or not. For that I would like to do something like: data checkClasses; className='com/mypath/MyClass'; output; className='com/mypath/MyClass2'; output; run; data checkResults(keep=className exists); Declare javaObj class('java/lang/Class'); class.exceptionDescribe(1); do until (last1); set checkClasses end = last1; class.callStaticVoidMethod('forName', className...

pginstaller
Log Message: ----------- Check for existing data directory during the GUI step. This prevents rollback during execution when initdb fails on existing data directory. Instead show a dialog with the reason and suggested fixes. Modified Files: -------------- pginst/ca: pginstca.c (r1.4 -> r1.5) (http://cvs.pgfoundry.org/cgi-bin/cvsweb.cgi/pginstaller/pginst/ca/pginstca.c.diff?r1=1.4&r2=1.5) ---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister...

Re: How to check, if a Java Class exists out of sas data step
On Mon, 11 Jun 2007 04:16:48 -0700, Richard A. DeVenezia <richard.google@DEVENEZIA.COM> wrote: >As you found out, javaobj can only instantiate a class that has a >public constructor. Additionally, javaobj interact with a method that >returns an object. Is there a reason you can not try to instantiate >MyClass directly ? > >In general, to deal with any method that returns an object, you need >to write an adapter class that has a series of javaobj accessible >methods for interacting with a delegate. Perhaps some future version >of SAS will have a fully realiz...

Export variable from GUI function to Workspace with checking if it already exists
Hi all, I'd like to export a variable form a running GUI to the workspace. I'd like to have the functionality that the variable name that the user has specified is automatically altered if the variable already exists in the workspace. The variable which should be exported is of the class 'tf' (transfer function), so "exist" does not work. Furthermore, think of that there might exist a variable with the same name but of another type (e.g.cell) It is just the functionality as it can be found with the linear analysis tool if linearized models or operating points are ...

Re: How to check, if a Java Class exists out of sas data step #2
It's interesting to observe the tunnel vision one can fall prey to when engaged in problem solving. You're so set on this idea of using java.lang.Class and the javaobj that when a wrapper class is suggested, you immediately dismiss it because you'd be forced to check for it's existence too. However, nothing forces you to check for the existence of the wrapper using javaobj! Surely, you will know it's name, since it's your wrapper class. And you do know it's a file. Don't you? ;-) P.S. Someone is bound to point out that being able to verify the wrapper'...

Checking for existance of feature / tools / solutions -- Something like Java webstart
Hi, I've tried searching this list & googling around a bit -- trying to see if there is a Java-Webstart like alternative for Python, the closest approximate I've found is something suggested in this post: http://mail.python.org/pipermail/python-list/2004-September/282837.html Is this still pretty much the state-of-art ? Or, is there some other, better, simpler, snappier alternative. My requirements fundamentally are to use the web-mechanism ("something" embedded in a webpage, that is able to detect whether particular (minimal) version of Python is installed on the cli...

How to run a gui from another existing gui.
Hi, I would like to open an existing gui, from another existing gui, with a push button. I have made both gui's using GUIDE. I can't get this to to work with either "run" or "open". Is there someone who can help me? -Anne "anne " <anneschow@hotmail.com> wrote in message <hqmp0v$6ol$1@fred.mathworks.com>... > Hi, > I would like to open an existing gui, from another existing gui, with a push button. I have made both gui's using GUIDE. > I can't get this to to work with either "run" or "open". > Is...

Web resources about - how to check if a certain JFrame exists - comp.lang.java.gui

Obama Is Going To Cuba, First U.S. President To Visit The Latin Nation In Almost A Century
U.S. President Barack Obama will reportedly visit Cuba next month, according to multiple diplomatic sources. The trip is scheduled some time ...

Kylie Jenner Signs On With Puma Despite Kanye West Twitter Protest – Will Kim Kardashian Play Peacekeeper ...
Kylie Jenner is definitely making sure fans know that she is her own person. It didn’t take long after Kanye West declared on Twitter that there ...

Opening Statements Begin in Islamic State Trial in Phoenix
Prosecutors have opened their case against a man they say was the driving force behind an Islamic State-inspired plot to attack an anti-Islam ...

Remains of the Day: Twitter Gets GIF Search
Twitter is making it easier to add animated GIFs to your tweets, thus saving the company and establishing it as the only social network you need. ...

28 killed in Ankara bomb attack on Turkish military - GlobalPost
At least 28 people were killed and 61 wounded Wednesday by a car bomb targeting the Turkish military in the heart of the capital Ankara, the ...

Samsung Galaxy J7 Hits The FCC
Whenever a particular device is close to a release, then you can be sure that it will make an appearance over at the FCC, although one should ...

Virtual Reality Therapy Could Be Used To Treat Depression
Could virtual reality be the next frontier for treating depression? A new study, published in the British Journal of Psychiatry Open on Monday, ...

Nike axes Manny Pacquiao over gay slurs: official
A Nike statement said the company had severed its ties with Pacquiao, who triggered a firestorm of controversy with his comments to a Filipino ...

U.S. and EU warn China on need to respect South China Sea ruling
By David Brunnstrom WASHINGTON (Reuters) - The United States and the European Union warned China on Wednesday that it should respect an international ...

You Can Now Access Gmail Features Without An @Gmail Address
It’s tough to get people to switch from one email service to another — getting a new email address might be even more annoying than having to ...

Resources last updated: 2/18/2016 8:14:43 AM