Trouble starting Swing app

Using the Java SDK with TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Mark Schnitzius

Trouble starting Swing app

Post by Mark Schnitzius »

I have a Swing application which I can run just fine from the command line. I can also run a text-only version of it from TextPad. But when I try to run the Swing version, it gets to where it tries to do the setVisible(true) and it just hangs. I have to close TextPad to make it stop.

I even have the problem when I try to run java.sun.com's "First Swing Program":

javax.swing.*;

public class HelloWorldSwing {
public static void main(String[] args) {
JFrame frame = new JFrame("HelloWorldSwing");
final JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}

It just hangs. Any idea why?
Jim Garacci

Re: Trouble starting Swing app

Post by Jim Garacci »

I've had this problem before (just about as annoying as the Nortons bug/feature). My resolution was to just never run Swing apps from textpad. Not the most elegant solution, I'll grant you.

Surely this is a sign of a process or thread related bug, but one can't be sure without further testing.
dano

Re: Trouble starting Swing app

Post by dano »

I have been working through Deitel&Deitel's book, "Java 2 - Introducing Swing". I have only had one minor bit of weirdness which I will mention later.

In looking at your code:
javax.swing.*;
public class HelloWorldSwing {
public static void main(String ...

I think you need an "import" keyword, before the javax.swing.*

import javax.swing.*;
public class HelloWorldSwing {
public static void main(String ...

Dano
Post Reply