472,811 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,811 software developers and data experts.

Aligning Items in JComboBox

I have a JComboBox with a list of numbers, from 1 digit to 5 digits.
Numbers with more than 3 digits have a comma in them.

I've been aligning them with leading spaces. Is there any simple and quick
way to align all the items in a JComboBox with the right edge of the box
(which, in this case, would mean all columns keep the same place value)?

Thanks!

Hal
Jul 17 '05 #1
3 4665
I've not tried this out but it might work...

myCombo.setRenderer(new DefaultListCellRenderer(){
public Component getListCellRendererComponent(
JList l,Object o,int i,boolean s, boolean f){
Component c=super.getListCellRendererComponent(l,o,i,s,f);
if(c instanceof JLabel)
((JLabel)c).setHorizontalTextPosition(SwingConstan ts.RIGHT);
}
});

If it doesn't, try changing "DefaultListCellRenderer" to
"javax.swing.plaf.basic.BasicComboBoxRenderer" ? Or look at the docs
for these classes.

Hal Vaughan <ha*@thresholddigital.com> wrote in message news:<nlB0c.152794$jk2.594715@attbi_s53>...
I have a JComboBox with a list of numbers, from 1 digit to 5 digits.
Numbers with more than 3 digits have a comma in them.

I've been aligning them with leading spaces. Is there any simple and quick
way to align all the items in a JComboBox with the right edge of the box
(which, in this case, would mean all columns keep the same place value)?

Thanks!

Hal

Jul 17 '05 #2
sorry - and "return c" afterwards!
Jul 17 '05 #3
S Manohar wrote:
I've not tried this out but it might work...

myCombo.setRenderer(new DefaultListCellRenderer(){
public Component getListCellRendererComponent(
JList l,Object o,int i,boolean s, boolean f){
Component c=super.getListCellRendererComponent(l,o,i,s,f);
if(c instanceof JLabel)
((JLabel)c).setHorizontalTextPosition(SwingConstan ts.RIGHT);
}
});

If it doesn't, try changing "DefaultListCellRenderer" to
"javax.swing.plaf.basic.BasicComboBoxRenderer" ? Or look at the docs
for these classes.
Thanks! I'll see how it works. If it doesn't, it also gives me a starting
point, so I can read up on DefaultListCellRenderer().

Hal

Hal Vaughan <ha*@thresholddigital.com> wrote in message
news:<nlB0c.152794$jk2.594715@attbi_s53>...
I have a JComboBox with a list of numbers, from 1 digit to 5 digits.
Numbers with more than 3 digits have a comma in them.

I've been aligning them with leading spaces. Is there any simple and
quick way to align all the items in a JComboBox with the right edge of
the box (which, in this case, would mean all columns keep the same place
value)?

Thanks!

Hal


Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: L L | last post by:
Dear all, Is it possible to set selected item a table row or in other ways, the editable JComboBox 's JTextField- can that be replace by a one row table? If possible, any direction of what...
1
by: - ions | last post by:
Hi, im a just wondering how to add elements into a JComboBox through a loop ie. just say i wanted to add the numbers 1 throught to 100. It seems easy but im having a bit of trouble. One problem...
1
by: Robert | last post by:
When I select a normal cell with a default editor for strings and press a letter key, the letter is automaticaly typed in the cell, but when I select a cell with an editable JComboBox editor and...
2
by: Dave | last post by:
Hello all, I need to know if you can vertically align Items within an ItemTemplate. For example I have two columns, one column has a stack of 6 textboxes, my second column can have 1 to n...
2
by: jerico | last post by:
Hi, I am developing an application for which I need to increase the size of the JComboBox.But it is not getting increased.I used the following technique: Container cont; JComboBox valueTypeBox ;...
8
by: dycharles | last post by:
I have a JComboBox loaded with 20,000 data, my problem is when i scroll down or scroll up, it is slower than the JComboBox with the smaller data. What can i do to make my JComboBox run faster or like...
2
by: thesti | last post by:
hi, How to, if user change the selected item of a JComboBox, it will enable another JComboBox. it's like a validation that the user has to select the year first, then the month, than the date. ...
2
by: HaifaCarina | last post by:
i have this unfinished java program and i can't figure out what is the problem.. please help... /** * @(#)Answer3.java * * * @author * @version 1.00 2008/1/17
2
by: javatech007 | last post by:
I am trying to use comboboxes in a ticket payment screen for train tickets. I have two combo boxes. One for picking a route and the other for picking a time. What i want is when you pick a route in...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.