Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing simple

 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I can't see any button in this form. Why?
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because a JFrame has a default BorderLayout.

Learn all about the standard AWT and Swing layout managers here.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use BorderLayout, But it doesn't work!


Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol : constructor BorderLayout()
location: class BorderLayout
at simplegui.Main.main(Main.java:19)
Java Result: 1

 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you,


?

But I think Darryl's point was that JFrame uses BorderLayout by default, and you weren't using it correctly or maybe it wasn't the right layout for your application. The link he provided was to give you details on how to use BorderLayout - or another layout - correctly.
 
Noel Alex
Greenhorn
Posts: 7
Fedora Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Counting the brackets is a good thing to make sure that you get not errors during compiling..

The class BorderLayout is may be required for import..

Here is working code:



INMHO:: There is tools such as Eclipse to help with code typo errors..


 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static method setPreferredSize(java.awt.Dimension) cannot be referenced from a static context
at simplegui.SimpleGui.main(SimpleGui.java:24)
Java Result: 1


I looked at this code in this site:



http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JPanel.html
 
Rob Spoor
Sheriff
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abalfazl hossein wrote:

That should be
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The button does not react.
 
Rob Spoor
Sheriff
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That code doesn't even compile. Please post a proper SSCCE.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I see this message:

Package frame does not exist.

Why this message appears?
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Rob said.
Rob Spoor wrote:That code doesn't even compile. Please post a proper SSCCE.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic