• Post Reply Bookmark Topic Watch Topic
  • New Topic

GridBagLayout ipadx help.  RSS feed

 
Michael Paul
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I am using GridBagLayout and I have a couple of JTextFields. I want to make them all the same width however, some of the JTextFields have text in them such as "Enter UserID" or something of that sort. So when I set the ipadx value, it seems to just add on to the width of the text inside the field. The problem with that, is that I don't want to have to figure out how long each each string is in order to make all the fields the same width. I could do that fo rthis small example but I was wondering what the best practice is. I'm sure there is an easy way around this...Does anyone know it? Sorry if this is a Noob question.

Thanks,
Michael
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A lot of people would write "Enter User ID" on a JLabel next to the JTextField. The whole idea of a LayoutManager is to allow the Components to alter their size to display their text, and ipadx/ipady mean the Components don't shrink smaller than the internal paddings + minimum sizes.

No problem about Noob questions; we all remember what it was like ourselves. I presume you are familair with the Java Tutorial about GridBag, but bet you don't know about Cai Horstmann's GBC class, and I am sure you haven't seen this tutorial.
 
Michael Paul
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response! I am not new to java, just to GridBagLayout...I usually work my way around having to use it. However, I understand that it is the most powerful layout manager, so I figure I should get comfortable with it.

You had mentioned just putting the JLabel next to the textfield...I do have that. This problem isn't really a "practical" one, it is just because I noticed this happens, and I was curious if there was a common solution to it. Maybe a more practical example of having to do this would be if you were asking the user to enter the version of something and you had a default value int he textfield explaining the format for the version...such as "#.##.##" or something of that sort.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!