• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adjust GUI

 
Ranch Hand
Posts: 570
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 3324
32
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:


 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic