File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

swing doesn't work

 
dodo dimitrius
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 349
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2823
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 349
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic