File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes trying to creat JFrame with buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "trying to creat JFrame with buttons" Watch "trying to creat JFrame with buttons" New topic
Author

trying to creat JFrame with buttons

Larry Reynolds
Greenhorn

Joined: Oct 22, 2005
Posts: 24
I am trying to create a JFrame called frame in a method TestGrid()and add a grid with buttons on it, here's the code so far. I was hoping someone could tell me why this doesn't show the button(s). thanks again.

public TestGrid(){
Jframe frame = new JFrame ("HelloWorldSwing");
this.setDefaultCloseOperation (JFrame.EXIT_ON_ClOSE);
JPanel content=new JPanel();
content.setLayout (new GridLayout(2,2));
content.add(new JButton ("Button1"));
this.setSize(300,300);
this.setVisible(true);
}
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
You haven't introducted the frame to your content pane.


There is no emoticon for what I am feeling!
Larry Reynolds
Greenhorn

Joined: Oct 22, 2005
Posts: 24
Thanks for the help, I've added the frame.setContentPane line but the window still doesn't show any buttons. I'll keep working on this. Thanks again.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
The code you gave (once I removed syntax errors) show a button:
Larry Reynolds
Greenhorn

Joined: Oct 22, 2005
Posts: 24
Thanks again, yes it works fine. I guess the reason my try didn't work is that the code I sent you was a "snippet". Thanks again.
 
Consider Paul's rocket mass heater.
 
subject: trying to creat JFrame with buttons
 
Similar Threads
Adding ScrollPane to JPanel
really basic GUI question
JPanels and JInternalFrames
How to place stuff without a layout?
Multiple JFrames ?