• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java GUI : JLabel size problem  RSS feed

 
Dávid Kéri
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,

as title shows, I'm having troubles setting the JLabels' sizes up properly.

I did some research before posting my problem, and as I understand, I can't exactly use setSize (or setPreferredSize, etc...) on a JLabel, because it changes its size automatically (or what). Maybe the LayoutManager has something to do with this? I could use some confirmation on this.

To be more accurate, my problem is shown on the following screenshot:


By courage88 at 2009-11-20

This JDialog is made up the following panels:
1) allPanel, that contains a leftPanel and a rightPanel, using a GridLayout(1,2)
2) leftPanel, that contains two JLabels, using GridLayout(2,1)
3) rightPanel that contains a JFormattedTextField and a JLabel, using GridLayout(1,2)

The problem is that the JLabels' areas are too long, they don't end up at the end of the String, but rather go on. I'd like to "cut" that off, make them shorter,so the whole Dialog will look much cooler.

Thanks for reading.
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dávid, you can specify the size and position of your controls if you don't set any layout manager - setLayout(null)!
 
Dávid Kéri
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you say I should just adjust the things manually? Also,why does the LayoutManager place so much empty space after the text in the JLabel? :/ I don't get it.
 
Rob Spoor
Sheriff
Posts: 20895
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GridLayout makes all of its cells as large as required to fit all components. That means that the largest width and largest height of all components will be the width and height of all components.

Moving to our GUI forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!