Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #5335
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
| Newsgroups | comp.lang.java.gui |
| Subject | Re: two labels in sequence, how hard can it be? |
| Date | Wed, 08 May 2013 00:12:21 +0200 |
| Organization | A noiseless patient Spider |
| Lines | 48 |
| Message-ID | <kmbu19$iok$1@dont-email.me> (permalink) |
| References | <labels-20130507223541@ram.dialup.fu-berlin.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Tue, 7 May 2013 22:08:41 +0000 (UTC) |
| Injection-Info | mx05.eternal-september.org; posting-host="394a1bbfa27080675b243c1d647ae0b0"; logging-data="19220"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NaJRCGr85vDWqkeELnvLZ" |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 |
| In-Reply-To | <labels-20130507223541@ram.dialup.fu-berlin.de> |
| Cancel-Lock | sha1:9i3DPzF+UkeQr9wNwpSBOj22Mi0= |
| Xref | csiph.com comp.lang.java.gui:5335 |
Show key headers only | View raw
On 07/05/2013 22:44, Stefan Ram allegedly wrote:
> I wanted to have a box starting with two labels, flush left, like:
>
> ..------------------------------------
> |[label alpha]
> |[label beta]
> |...
>
> . Turned out, to add such a label, I had to do all of the following:
>
> final javax.swing.Box vbox = javax.swing.Box.createVerticalBox();
> { final javax.swing.Box hbox = javax.swing.Box.createHorizontalBox();
> final javax.swing.JLabel label = new javax.swing.JLabel( "alpha" );
> hbox.add( label );
> hbox.add( javax.swing.Box.createGlue() );
> hbox.setMaximumSize
> ( new java.awt.Dimension
> ( java.lang.Integer.MAX_VALUE, label.getHeight() ));
> vbox.add( hbox ); }
> ....
>
> When I add the label to the vbox directly (without an hbox),
> it is not precisely aligned left, even when left alignment
> is request. There still seemed to be some »glue« on the left
> of it, which I did not add there.
>
> When I do not setMaximumSize, the height of the hbox is much
> larger than the height of the label, that is: too large.
>
> But maybe my solution is too complicated? Is there a more
> simple solution that I am not aware of?
>
Never liked Box'es much...
- GridBagLayout
- weightx = 1; weighty = 0; anchor = EAST; gridx = 0; gridy = 0;
- add first label;
- ++gridy;
- add second label;
If the Panel is bigger than those two labels and you want them pushed to
the top:
- ++gridy; weighty = 1
- add Box.createGlue();
--
DF.
Back to comp.lang.java.gui | Previous | Next — Next in thread | Find similar
Re: two labels in sequence, how hard can it be? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-05-08 00:12 +0200 Re: two labels in sequence, how hard can it be? FredK <fred.l.kleinschmidt@gmail.com> - 2013-05-08 13:20 -0700
csiph-web