This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display the grid border for GridBagLayout

 
Fox Shen
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now for displaying the Search criteria with some GridBagLayout, the code as following:

As the displaying result is so 'flat', I want to add some border line for each grid so as to make it looks like some table format. I tried to set some Border such as LineBorder, I even create some Border as GridLindBorder, but due to the size of each component are different, so the Border idea seems not work.
Anyone know any other solution for above problem please give some comment here. I would appreciate very much.
 
Mag Hoehme
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fox,
don't take too much pain for the GUI. Swing offers a lot of modifications - and you run into the risk of writing source code that is difficult to read. I've heard that people got deductions for this reason.
IMHO the best thing is to keep things as simple as possible, without too many embellishments.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fox,
I have to agree with Mag and would add that maybe you might want to trash the GridBagLayout. You can achieve the same thing with a combination of GridLayout, BorderLayout and FlowLayout, although you won't have absolute control.
Hope this helps,
Michael Morris
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey I used the GridBagLayout. I like it alot, it gives me complete flexibility without worring if I made the right combination of BorderLayout, GridLayout, FlowLayout, within a BorderLayout around a FlowLayout.
However did create a GridBagConstraintsHelper class that I could change only the little thing I needed changed form the time before, which made things really easy.
I would still not try to make any borders around components. Not worth the trouble.
Mark
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Mark Spritzler:
Hey I used the GridBagLayout.

I admire anyone who will take on a grizzley face to face Actually, I started out with a GridBag and finally decided on the lazy way
Michael Morris
 
Fox Shen
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mag, Michael and Mark
It seems that I've thought too much for the UI feel. Ok, now I'll pay more attention to my code style and so on. Simple and useful will be my new target. So thanks for your comments.
Hi Mark,

However did create a GridBagConstraintsHelper class that I could change only the little thing I needed changed form the time before, which made things really easy.

Can you share some thoughts on your GridBagConstraintsHelper class, I found my own code for UI(by using GridBagLayout) seems a little boring, what about your good idea for that?
--Fox
 
Mag Hoehme
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am also fond of GridBagLayout: Once you know how to handle it, you will never use any other layout manager.
I learned to control it in the RHE Layout chapter. It's a really good how-to.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I surrender and I'm coming out of the closet. I have always been a secret GridBagLayout admirer myself and vow to never disparage it again.
Michael Morris
[ September 01, 2002: Message edited by: Michael Morris ]
 
jj wilson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found a cheep solution,

Set the background of your entire area to be dark
this.setBackground(new Color(100, 100, 150));

then for each item that you add, set it to be white and opaque
custName.setBackground(Color.WHITE);
custName.setOpaque(true);

add items to your GridBagLayout using the following constraints:

constraints.fill = GridBagConstraints.BOTH;
constraints.insets=new Insets(2, 2, 2, 2);

This inset creates the border area of 4 pixels wide.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, JJ. Welcome to JavaRanch!

Champion, I'd kindly like to ask you not to wake up such old threads. The assignment they were talking about was the Fly By Night, which isn't even assigned anymore nowadays. When you have a question, or even something to share, please start a new thread. For such, please CarefullyChooseOneForum, that is, select the most appropriate forum for your question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic