Thread View: borland.public.jbuilder.java.swing
3 messages
3 total messages
Started by dingfeldera
Wed, 25 May 2005 02:45
JComboBox Text Alignment
Author: dingfeldera
Date: Wed, 25 May 2005 02:45
Date: Wed, 25 May 2005 02:45
2 lines
987 bytes
987 bytes
How can I make the text in a JComboBox align to the right instead of the left?
Re: JComboBox Text Alignment
Author: 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
Re: JComboBox Text Alignment
Author: dingfeldera
Date: Thu, 26 May 2005 05:33
Date: Thu, 26 May 2005 05:33
5 lines
1156 bytes
1156 bytes
Excellent. That works great. If anyone else is doing this, remember to set the renderer so the combo box uses it i.e. mycombobox.setRenderer(renderer);
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads