invokeLater

I

Ike

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();
}
 
S

Steve W. Jackson

"Ike said:
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?
 
M

Michael Rauscher

Ike said:
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
 
D

Daniel Pitts

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)
 
T

Tom Hawtin

Ike said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top