Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

New to SWING

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i am not new to Java but i am new to SWING. I developed GUI in the past in Tcl/Tk and other languages and libraries but now i found SWING very hard to use. I simply want to create something like in the attached picture, in the simplest way. Hope to be clear.
Untitled.png
[Thumbnail for Untitled.png]
 
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Pasquale,

welcome to the Ranch and enjoy the stay!

Swing is indeed not simple, and you should probably invest your time in JavaFX.

Here is a way to achieve your layout. It uses a couple of JPanels with varying LayoutManagers. For label 1, I used a panel with a FlowLayout.LEFT. For the other labels I used panels with a FlowLayout.center. And to get that left gap between label 1 and label 3 I used a panel with just one label. And I added these panels to the contentpane of the frame.

A GridBagLayout is probably possible as well, but I did not give that a try.

 
Pasquale Villani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:hi Pasquale,

welcome to the Ranch and enjoy the stay!

Swing is indeed not simple, and you should probably invest your time in JavaFX.



Thanks. I have already guessed that SWING is not easy and simple. Your solution works well however does not make me happy in the sense i like simple and logic code (that Java is not in this case), unfortunately now i am forced to use it.
 
Saloon Keeper
Posts: 23440
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, I'm a little surprised that Swing would be hard after Tcl/Tk. Both rely on relative layouts. It's the people who are used to absolute layouts that find systems like Swing (and Tcl/Tk and Android) to be especially frustrating.

The names of they layout managers may be different and there may be a few layout managers that are unique to Tcl/Tk or to Swing, but the overall concept is the same. You nest different layouts to hold the controls, and adjust layout properties to fine-tune their behavior.
 
Pasquale Villani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I developed for years in Tcl/Tk and i confirm that SWING is similar but not the same, Tk is more flexible and much more simple, permiting to create complex GUI quickly and easly.
 
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic