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

Adjust GUI  RSS feed

 
John Joe
Ranch Hand
Posts: 281
2
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I trying to create a GUI, where the image is beside the text.



When I run the file, the frame (A)looked like this although I add in frame.

And this is how my GUI (B) looked. Why the image did not placed in the right hand side of text ?



z.PNG
[Thumbnail for z.PNG]
B GUI Looked
Capture.PNG
[Thumbnail for Capture.PNG]
A
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by reading the Swing tutorial on Layout Managers. Download some of the demo code to learn how to better structure your code. For example:

1. All GUI code should be executed on the Event Dispatch Thread (EDT). That is why SwingUtilities.invokeLater(...) is used in all the examples.
2. You should not extend JFrame.
3. Don't use setSize() or setBounds(). Instead you just use frame.pack() AFTER all components have been added to the panel.

Why the image did not placed in the right hand side of text ?


The panel is using a GridLayout and the layout manager will determine the size and location of each component based on the order the component is added to the frame. See point 3 from above.

The code should be:


 
Fred Kleinschmidt
Bartender
Posts: 507
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why have separate labels for the text and icon? They can be put in a single label:


You can use combined.setIconTextGap( gap ) to adjust the spacing if the default is not to your liking.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!