Article View: borland.public.jbuilder.java.swing
Article #453Re: JComboBox Text Alignment
From: John McGrath [TeamB]
Date: Wed, 25 May 2005 08:38
Date: Wed, 25 May 2005 08:38
22 lines
1602 bytes
1602 bytes
On 5/24/2005 at 10:45:44 PM, dingfeldera wrote:
> How can I make the text in a JComboBox align to the right instead
> of the left?
You need to provide a renderer that renders the item the way you want.
Since a DefaultListCellRenderer is also a JLabel, you could create one
with the following code:
ListCellRenderer renderer = new DefaultListCellRenderer();
( (JLabel) renderer ).setHorizontalAlignment( SwingConstants.RIGHT );
If your combo box is editable, you will also want to provide an editor.
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID:
<xn0e2nrgqiy68h0008@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<4293e6d8$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,c898ba6b3257738e X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit From: "John McGrath [TeamB]" <ng-b@JPMcGrath.net> Subject: Re: JComboBox Text Alignment Newsgroups: borland.public.jbuilder.java.swing References: <4293e6d8$1@newsgroups.borland.com> User-Agent: XanaNews/1.17.4.1 Message-ID: <xn0e2nrgqiy68h0008@newsgroups.borland.com> X-Ref: newsgroups.borland.com ~XNS:0000041A MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 NNTP-Posting-Host: 151.197.212.47 Date: 25 May 2005 01:38:20 -0700 X-Trace: newsgroups.borland.com 1117010300 151.197.212.47 (25 May 2005 01:38:20 -0700) Lines: 22 X-Authenticated-User: jpmcgrath Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail