473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 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 4699
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.