aspose file tools*
The moose likes Beginning Java and the fly likes swing doesn't work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "swing doesn Watch "swing doesn New topic
Author

swing doesn't work

dodo dimitrius
Greenhorn

Joined: Dec 04, 2001
Posts: 24
I've been trying to display a frame, with two buttons using swing. The file compiled, and when I run it, it displays a grey empty box(frame). I tried 'swing' examples from a book, and again, grey box, with nothing in it.
I rewrote the file using awt, and it works fine.
I am using SDK 1.4.0 beta 3, on WIN98SE.
Any idea?
Berko
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
Try out the following example and let me know that it runs on your platform or not :

Good luck
Rashid Ali
[ January 22, 2002: Message edited by: Rashid Ali ]
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Why don't you show us your code. Are you by chance creating an Applet with Swing? If so, you need the plug in to get it to run.
dodo dimitrius
Greenhorn

Joined: Dec 04, 2001
Posts: 24
Hi guys!
Rashid, I tried your code, and the result is the same, the frame (grey box) displays with no elements on it(button and textfield).
Paul, here is my code:
import java.awt.*;
import javax.swing.*;
public class BoxStacker {
public static void main(String[] args) {
JPanel p = new JPanel();
p.add(new JButton("Save"));
p.add(new JButton("Hello"));
JFrame f = new JFrame("Berko");
f.getContentPane().add(p);
f.setSize(200,200);
f.setVisible(true);
}
}
It displays the frame with the name on it, but there is no buttons inside, just grey empy box.
Any idea?
Berko
Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
Dear Berko
I tried your code and it works fine shows two buttons on the little frame having title 'Save' and 'Hello'. I did not made any change in your code just compiled and run.
I think there's some problem with you J2SDK1.4 due to which it's not working on your computer.
Reinstall it again and try your code it will definitely works fine.
Hope it helps.
Rashid Ali
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: swing doesn't work
 
Similar Threads
Greying a Textbox
Two windows get focus in turn depends on user action?
Drawing a rectangular box
JComboBox and ArrayList
Swing Window Communication.