Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2004

Tip: Looking for answers? Try searching our database.

Setting start position for JLabel

Thread view: 
Mike - 14 Jan 2004 21:34 GMT
Hello, Is there a way of setting text for a JLabel after a certain amount of
empty characters.
For example, I want to avoid doing this

   JLabel label = new JLabel();
   label.setText("                                   Book Name =")

Thanks
Steve W. Jackson - 14 Jan 2004 22:30 GMT
>:Hello, Is there a way of setting text for a JLabel after a certain amount of
>:empty characters.
[quoted text clipped - 4 lines]
>:
>:Thanks

You'll find that using those spaces still won't work right anyway in
some cases.  The text of a JLabel is usually centered on the label.  To
have control over that implies that you need control over the size of
the JLabel, possibly over its placement with its parent container, and
even the Font used to display its text.  In our app, we specified the
font we wanted to use, then devised a means of building JLabels and
other components using a formula for specifying the sizes (min, max, and
preferred).

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama

ak - 15 Jan 2004 00:49 GMT
> Hello, Is there a way of setting text for a JLabel after a certain amount of
> empty characters.
[quoted text clipped - 4 lines]
>
> Thanks

first determine needed length then add EmptyBorder to JLabel:

label.setBorder(new EmptyBorder(0, length, 0, 0));

--

____________

http://reader.imagero.com the best java image reader.
Thomas Weidenfeller - 15 Jan 2004 07:28 GMT
> Hello, Is there a way of setting text for a JLabel after a certain amount of
> empty characters.
> For example, I want to avoid doing this
>
>     JLabel label = new JLabel();
>     label.setText("                                   Book Name =")

Use a suitable layout manager instead, and align all components in that
column to the right.

Also, the common standard in GUIs is to separate the label and the data
with a ":", not with " =".

/Thomas
Fred L. Kleinschmidt - 15 Jan 2004 15:06 GMT
> Hello, Is there a way of setting text for a JLabel after a certain amount of
> empty characters.
[quoted text clipped - 4 lines]
>
> Thanks

If you are using a layout manager that controls its size, or setBounds
to specify the size, use:
label.setHorizontalAlignment(SwingConstants.RIGHT);
Signature

Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94  (206)544-5225



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.