Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

JWindow Refuses To Show

$
0
0
I'm really pulling my hair out on this one, guys.

I have finished developing my program. The one problem I am having is simply showing a "Connecting to Server" message while the program attempts to contact a listener on another computer. The computers connect fine when they are supposed to. However, I simply cannot get the JWindow to show "Connecting to Server". It won't show at all. I have tried everything I've found in google searches and nothing is working.

The part that is making me pull my hair out is the fact that the same code works perfectly when used in a self contained program but it simply refuses to work when called from within my program.

package clock;

import java.awt.*;

import javax.swing.*;

public class WaitScreen extends JWindow {
	
	private TimeClock timeClock;
	
	public WaitScreen(TimeClock tc) {
		super(tc);
		timeClock = tc;
		
		JPanel mainPanel = new JPanel();
		mainPanel.setLayout(new BorderLayout());
		
		JPanel messagePanel = new JPanel();
		messagePanel.setBackground(Color.white);
		messagePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		JLabel message = new JLabel("Connecting to server...");
		message.setFont(new Font("Arial", Font.BOLD, 14));
		message.setForeground(Color.black);
		messagePanel.add(message);
		
		mainPanel.add(new JLabel(""), BorderLayout.NORTH);
		mainPanel.add(messagePanel, BorderLayout.CENTER);
		mainPanel.add(new JLabel(""), BorderLayout.SOUTH);
		
		getContentPane().add(mainPanel);
		pack();
		setLocation((int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2 - this.getWidth()/2), 100);
		revalidate();
		getContentPane().setVisible(true);
		setVisible(true);
	}
	
}



If you try this code in its own self contained program, it will work fine. But it simply refuses to show when used in my program.

Even more baffling is the fact that if you cause an exception to be thrown by adding the following line to the end of the code, the JWindow will FINALLY show, but the exception causes the program to stop and the server is never contacted.
timeClock.getContentPane().add(this);


I tried adding the JWindow to timeClock (which extends JFrame) and, of course, you can't do that and an exception is thrown. But when this occurs, the JWindow WILL show. Remove that faulty code, and JWindow no longer shows.


Any ideas? This one is really baffling to me.

Viewing all articles
Browse latest Browse all 51036

Trending Articles