• 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

laying components

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,

I've a JPanel which has GridBaglayout.Now i want to lay components in horizontally say a label and a text field.
I want that paricular grid to have the background as Light Blue and these components sitting on that background.
I know one way is to do having panel with Blue color and placing these two components on that panel.Then placing this panel over the grid layout cells.This is very tediuos as i'll be having several comaponents to be layed with blue background in row wise(can't have JTable cells here!!!).Can somebody suggest better idea.
Thanks in advance
Prashanth
 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
easier way is to just setLayout(null) setBounds(x,y) on your components with in your jpanel.

then you could paint blue around your textfield and label.

labels are ok, g.drawString("string",x,y); is just as easy.

Justin
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Justin Fox:
easier way is to just setLayout(null) setBounds(x,y) on your components with in your jpanel.



Easier? Yes. Good? NO!

Unfortunately, Prashanth, GUI layouts are tedious. Sometimes tedious and development go hand in hand. I honestly don't know of a better way to do what you are requesting. When I've had to lay repetitive panels on panels I usually create some sort of factory class or methods to generate the nasty bits over and over. So I might have a method that takes 1 or more components and returns my blue JPanel with these 2 components on them. So the code you write over and over becomes:

JPanel panel = createBluePanel(someLabel, someTextField);

And createBluePanel does the tedious work. I would like to point out that there are much better layout managers than what Swing ships with. JGoodies Form Layout for example. Might see if this takes some of the tedious work out of it.
[ April 03, 2007: Message edited by: Gregg Bolinger ]
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
good enough to ace software engineering lol...


Justin
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Software Engineering != GUI Design
 
Prashanth Bhanu
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks friends,

This particular job is paused for the moment as some thing else is being assigned to me.
I want to want to post relevent topic as a new message.
thanks once again.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
software engineering ~ GUI design
 
I want my playground back. Here, I'll give you this tiny ad for it:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic