🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
4 messages
4 total messages Started by Innominate Innominate Sun, 07 Nov 2004 04:48
Best way to auto-format buttons and such inside a JPanel.
#892
Author: Innominate Innominate
Date: Sun, 07 Nov 2004 04:48
7 lines
1335 bytes
I'm trying to add a number of simple Swing elements to a JPanel that is 
using a GridLayout. When I add a JComboBox to the panel, the box is 
sized so as to entirely fill its portion of the grid. Is there a setting 
I can make so that the box's size can be determined, probably at 
runtime, in an appropriate way, given the font in use at the time?

Innominate
Re: Best way to auto-format buttons and such inside a JPanel.
#893
Author: John McGrath [TeamB]
Date: Sun, 07 Nov 2004 23:52
25 lines
1957 bytes
On 11/6/2004 at 11:48:24 PM, Innominate Innominate wrote:

> I'm trying to add a number of simple Swing elements to a JPanel 
> that is using a GridLayout. When I add a JComboBox to the panel, 
> the box is sized so as to entirely fill its portion of the grid.
> Is there a setting I can make so that the box's size can be 
> determined, probably at runtime, in an appropriate way, given
> the font in use at the time?

A GridLayout always lays out each child component at the same size.
You could place a panel in the grid, and your component in the panel, 
so that the panel's layout would determine the size and placement of
the component within the grid cell.

You might also want to look at other layouts, such as GridBagLayout.  
It  has the features that you are asking for.

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: Best way to auto-format buttons and such inside a JPanel.
#900
Author: Innominate Twice
Date: Mon, 15 Nov 2004 03:35
29 lines
2365 bytes
"John McGrath  [TeamB]" <ng-b@JPMcGrath.net> wrote in message news:<xn0dphnkf8ocbk002@newsgroups.borland.com>...
> On 11/6/2004 at 11:48:24 PM, Innominate Innominate wrote:
> 
> > I'm trying to add a number of simple Swing elements to a JPanel 
> > that is using a GridLayout. When I add a JComboBox to the panel, 
> > the box is sized so as to entirely fill its portion of the grid.
> > Is there a setting I can make so that the box's size can be 
> > determined, probably at runtime, in an appropriate way, given
> > the font in use at the time?
> 
> A GridLayout always lays out each child component at the same size.
> You could place a panel in the grid, and your component in the panel, 
> so that the panel's layout would determine the size and placement of
> the component within the grid cell.
> 
> You might also want to look at other layouts, such as GridBagLayout.  
> It  has the features that you are asking for.

Okay, I added a Grid layout, with 2 columns to my panel. Then I added
JPanels to 6 grid areas and a GridBag layout to each. To test this, I
added a JComboBox to a few of the panels. The combo box formatted
nicely w/o any difficulty and appeared the same when I executed the
program as it did when I designed it.

Thank You. I've been hearing about GridBag layouts and that they
should be used with nested layouts but I also heard that they were
difficult for beginners to work with. This is encouraging.

Thanks again,
Re: Best way to auto-format buttons and such inside a JPanel.
#901
Author: Inominate Inominate
Date: Tue, 16 Nov 2004 02:02
32 lines
2512 bytes
John McGrath [TeamB] wrote:
> On 11/6/2004 at 11:48:24 PM, Innominate Innominate wrote:
> 
> 
>>I'm trying to add a number of simple Swing elements to a JPanel 
>>that is using a GridLayout. When I add a JComboBox to the panel, 
>>the box is sized so as to entirely fill its portion of the grid.
>>Is there a setting I can make so that the box's size can be 
>>determined, probably at runtime, in an appropriate way, given
>>the font in use at the time?
> 
> 
> A GridLayout always lays out each child component at the same size.
> You could place a panel in the grid, and your component in the panel, 
> so that the panel's layout would determine the size and placement of
> the component within the grid cell.
> 
> You might also want to look at other layouts, such as GridBagLayout.  
> It  has the features that you are asking for.
> 

Okay, I added a Grid layout, with 2 columns to my panel. Then I added
JPanels to 6 grid areas and a GridBag layout to each. To test this, I
added a JComboBox to a few of the panels. The combo box formatted
nicely w/o any difficulty and appeared the same when I executed the
program as it did when I designed it.

Thank You. I've been hearing about GridBag layouts and that they
should be used with nested layouts but I also heard that they were
difficult for beginners to work with. This is encouraging.

Thanks again,
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads