Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Only the frame with frame name is visible..inside blank  RSS feed

 
mike Vigor
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so i started learning java gui yesterday! Especially swing! So is learning about event and handling event time!
the book am using says this code should display the frame and inside the frame the a list and at least the ok button...the code looks right..
but when i compile i only see the Frame with the frame name Event Object..inside the frame is all blank!
Can someone tell me why ?
I'm using eclipse ide.
thanks in advance!

 
K. Tsang
Bartender
Posts: 3624
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

You need to add the panel to the frame. You can that like



JFrame default layout manager is BorderLayout.

Since you set the layout for the JPanel to null, I don't know you how the table and button will show up, if it will show up. JPanel default layout manager is FlowLayout.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Since you set the layout for the JPanel to null, I don't know you how the table and button will show up, if it will show up.

Since the bounds of the JList (not table) and JButton have been set, they will show up. That said, it is much better for mike to learn and use an appropriate layout manager.

mike, I see a lot of stuff in that code that the author *probably* thought would serve as a learning aid, stuff that you would need to un-learn as quickly as possible once you get familiar with Swing coding. For example, testing the ID of an ActionEvent -- it will always be equal to ActionEvent.ACTION_PERFORMED, so the test is redundant. Then, KeyEvent provides API for getKeyModifiersText(...) so there's really no need to roll your own.

Have you discovered the Oracle tutorials? There's a very good section on Creating a GUI With Swing (but skip the section on NetBeans).

And welcome again!

 
Campbell Ritchie
Sheriff
Posts: 53743
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

Which book is that? Please tell us to avoid copyright problems and also because that looks too complicated for you to be using on your first day with Swing.
 
mike Vigor
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the book is
Created by dovari.sudheerkiran@gmail.com
The Java Swing tutorial pdf
downloaded free from the internet

well it may look complicated for a starter..but I already know some programming so I think is just fine and well am willing to dig into it as fast as possible so....no stopping me :P
thanks to you all guys for your answers..just adding the panel solved everything
 
Campbell Ritchie
Sheriff
Posts: 53743
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume you mean this tutorial.
 
mike Vigor
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A quick question since we're already at it...can I make my buttons shape hexagonal?
 
Campbell Ritchie
Sheriff
Posts: 53743
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am pretty sure you can create hexagonal buttons but I don't know how.
 
mike Vigor
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
telling me is possible brightens the day a bit..but you not knowing how is not helpful at all haha..
anyway I'm late on a project and I have to be quick...I need to implement a hexagonal grid where clicking on a hex makes something happens else where..through listeners and stuff we can solve that...
so was thinking if I could have my buttons in a hex shape then with a proper layout and filling the frame with all those buttons i already have my grid... this is a solution i came up with...

or else I have to learn graphics2d quickly and learn to implement a cartesian plane and draw hex grid inside with coordinates and stuff and make them too listen for events and bla bla bla..i find this solution more tough...any good
ideas on the way forward?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!