🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #13329

Re: Adding a JComponent to a JToolBar

#13329
From: John P. McGrath
Date: Wed, 12 Aug 1998 00:00
37 lines
2083 bytes
mnemonic <mnemonic@mmc.mmu.ac.uk> wrote:

> You should set the layout of your JToolBar to BorderLayout.
> Then add your JComboBox object to the JToolBar contatiner.
> Then set the constrains property of the JComboBox object to CENTER.
> 
> Your JComboBox will now be displayed in the center of the JToolBar.

This doesn't sound right at all.  You may be able to do this, but what about other components in the JToolBar?

I have seen similar behavior when I added different size components to a toolbar.  But I did not investigate it much, since the components were supposed to be the same size.

I did see that JToolBar uses a BoxLayout, which I have also had problems with.  I also noted that the Basic UI delegate for JToolBar sets the LayoutManager for the JToolBar, so to change the LayoutManager, you might have to provide your own UI delegate.

If you make the JToolBar non-floatable, it might make it easier to deal with.  The code in BasicToolBarUI that sets the layout is in the setOrientation() method, which I think gets called when the JToolBar is docked.

Another approach would be to create a JPanel with all of your JToolBar components in it, set the LayoutManager to whatever you would like, and then add the JPanel as the only component in the JToolBar.  Of course, with this approach, the orientation of the JToolBar could not be changed.

-- 
John P. McGrath
<mcgrath@enter.net>
<jpm@nscs.fast.net>

Technical Details
Message-ID: <01bdc5ca$1bd7b8f0$1a47aacc@ferd>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <6qdgji$g1j11@forums.borland.com> <35CC8398.D215262D@mmc.mmu.ac.uk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,2f1067e24665c53c
X-Google-Attributes: gid111d45,public
From: "John P. McGrath" <mcgrath@enter.net>
Subject: Re: Adding a JComponent to a JToolBar
Date: 1998/08/12
Message-ID: <01bdc5ca$1bd7b8f0$1a47aacc@ferd>
X-Deja-AN: 380335571
Content-Transfer-Encoding: quoted-printable
References: <6qdgji$g1j11@forums.borland.com> <35CC8398.D215262D@mmc.mmu.ac.uk>
Content-Type: text/plain; charset=ISO-8859-1
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing