Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Nigel Wade Newsgroups: comp.lang.java.programmer Subject: Re: How to move text within Jlabels to the right Date: Fri, 12 Apr 2013 15:07:39 +0100 Lines: 23 Message-ID: References: <334f5820-444d-409b-ab37-913a2bc6a6d5@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net eARaG5a7Gyly51Pp9cDITQ0mBeN/+dlFwEPBnmkqfU3hOUUUod Cancel-Lock: sha1:u70GcaGDuF+cMlgUiGJEyhwR1AE= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120601 Thunderbird/13.0 In-Reply-To: <334f5820-444d-409b-ab37-913a2bc6a6d5@googlegroups.com> Xref: csiph.com comp.lang.java.programmer:23429 On 12/04/13 14:12, clusardi2k@aol.com wrote: > I have two JLabels with different lenght of text. One JLabel is below the other. I'd like to get the two "colons" in them to line-up vertically. > > I tried padding one with "space" characters, but that didn't line up perfectly. My guess is that certain characters have different widths. > > (I tried the align vertical and horizontal properties, etc but they didn't work.) > > Eg, In the below text of two JLabels, the addition of a space character didn't line up the two colons. > > Label1 My First Name: > Label2 Last Name: > > Thanks, > Place them in a JPanel, and set a layout manager which allows you to align them. GridBagLayout will do this. Align them with java.awt.GridBagConstraints.EAST, or LINE_END so they are at the right of the JPanel. The Tutorial has all the gory details: http://docs.oracle.com/javase/tutorial/uiswing/layout/index.html -- Nigel Wade