Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > invokeLater

Reply
Thread Tools

invokeLater

 
 
Ike
Guest
Posts: n/a
 
      02-01-2007
Can anyone please tell me why my invokeLater in the following code never
displays the JFrame I am trying to get it to display, and shows no
exceptions either? I am certain I must have somethign stupid and wrong here.
Thanks, Ike

public void putupreconnectnotice(boolean on){
if(on){
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
connectionLost();
}
});
}else{
if(waitjframe!=null){
waitjframe.dispose();
}
}
}

private void connectionLost(){
waitjframe = new JFrame("Connection to server lost!");
waitjframe.setSize(310, 75);
waitjframepanel=new JPanel();
waitjframepanel.setPreferredSize(new Dimension(300,60));
waitjframepanel.setBackground(Color.WHITE);
waitjframepanel.add(new JLabel("Attempting to reconnect"));
waitjframe.getContentPane().add(waitjframepanel);
waitjframe.pack();
waitjframe.setVisible(false);
waitjframepanel.grabFocus();
}


 
Reply With Quote
 
 
 
 
Steve W. Jackson
Guest
Posts: n/a
 
      02-01-2007
In article <YEpwh.19528$(E-Mail Removed) .net>,
"Ike" <(E-Mail Removed)> wrote:

> Can anyone please tell me why my invokeLater in the following code never
> displays the JFrame I am trying to get it to display, and shows no
> exceptions either? I am certain I must have somethign stupid and wrong here.
> Thanks, Ike
>
> public void putupreconnectnotice(boolean on){
> if(on){
> javax.swing.SwingUtilities.invokeLater(new Runnable() {
> public void run() {
> connectionLost();
> }
> });
> }else{
> if(waitjframe!=null){
> waitjframe.dispose();
> }
> }
> }
>
> private void connectionLost(){
> waitjframe = new JFrame("Connection to server lost!");
> waitjframe.setSize(310, 75);
> waitjframepanel=new JPanel();
> waitjframepanel.setPreferredSize(new Dimension(300,60));
> waitjframepanel.setBackground(Color.WHITE);
> waitjframepanel.add(new JLabel("Attempting to reconnect"));
> waitjframe.getContentPane().add(waitjframepanel);
> waitjframe.pack();
> waitjframe.setVisible(false);
> waitjframepanel.grabFocus();
> }


Perhaps it's because your connectionLost method specifically calls
setVisible(false) on the frame?
--
Steve W. Jackson
Montgomery, Alabama
 
Reply With Quote
 
 
 
 
Michael Rauscher
Guest
Posts: n/a
 
      02-01-2007
Ike schrieb:
> Can anyone please tell me why my invokeLater in the following code never
> displays the JFrame I am trying to get it to display, and shows no
> exceptions either? I am certain I must have somethign stupid and wrong here.
> Thanks, Ike


Apart from the possibility of passing false to putupreconnectnotice, I'd
expect that this

> waitjframe.setVisible(false);


isn't what you really want

Bye
Michael
 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      02-01-2007
On Feb 1, 9:43 am, "Ike" <(E-Mail Removed)> wrote:
> Can anyone please tell me why my invokeLater in the following code never
> displays the JFrame I am trying to get it to display, and shows no
> exceptions either? I am certain I must have somethign stupid and wrong here.
> Thanks, Ike
>
> public void putupreconnectnotice(boolean on){
> if(on){
> javax.swing.SwingUtilities.invokeLater(new Runnable() {
> public void run() {
> connectionLost();
> }
> });
> }else{
> if(waitjframe!=null){
> waitjframe.dispose();
> }
> }
> }
>
> private void connectionLost(){
> waitjframe = new JFrame("Connection to server lost!");
> waitjframe.setSize(310, 75);
> waitjframepanel=new JPanel();
> waitjframepanel.setPreferredSize(new Dimension(300,60));
> waitjframepanel.setBackground(Color.WHITE);
> waitjframepanel.add(new JLabel("Attempting to reconnect"));
> waitjframe.getContentPane().add(waitjframepanel);
> waitjframe.pack();
> waitjframe.setVisible(false);
> waitjframepanel.grabFocus();
> }


As others have pointed out
you might want to setVisible(true) instead of setVisible(false)

 
Reply With Quote
 
Ike
Guest
Posts: n/a
 
      02-01-2007
Yep....that was it....I just couldn;t see it. Thanks so much guys. -Ike


 
Reply With Quote
 
Tom Hawtin
Guest
Posts: n/a
 
      02-03-2007
Ike wrote:
>
> public void putupreconnectnotice(boolean on){
> if(on){
> javax.swing.SwingUtilities.invokeLater(new Runnable() {
> public void run() {
> connectionLost();
> }
> });
> }else{
> if(waitjframe!=null){
> waitjframe.dispose();
> }
> }
> }


Not the problem you were having, but dispose should be run in the EDT as
well as showing the frame.

private volatile boolean notice;
public void setNotice(boolean notice){
this.notice = notice;
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
if (MyClass.this.notice) {
connectionLost();
} else {
if (noticeFrame != null){
noticeFrame.dispose();
}
}
}
});
}

Tom Hawtin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
invokeLater with JTreeTable == event-dispatch thread? soup_or_power@yahoo.com Java 1 11-23-2005 04:48 PM
eventqueue.invokelater in main method Richie Java 13 10-29-2005 05:59 PM
Can someone use invokeLater() to call a public method from a JPanel? ***C.Steamer*** Java 39 10-29-2004 02:00 PM
SwingUtilities.invokeLater Ike Java 2 10-08-2003 08:47 PM
InvokeLater Mohit Gupta ASP .Net 0 07-11-2003 07:34 AM



Advertisments