Solved

How to align strings in a swing.jList?

Posted on 2002-07-17
5
1,223 Views
Last Modified: 2012-05-04
The text in my swing.jList is not align even if I use a padRight function. What is weird is that when I print this text with "System.out.println", all the lines are align correctly. Any suggestions?  

there is some codes:

Vector temp2 = new Vector();
        for(int i=0; i<group.list.size(); i++)
            temp2.add(StringHelper.padRight(((Html)group.list.get(i)).IfIndex, 10) +
            StringHelper.padRight(((Html)group.list.get(i)).Description, 25) +
             ((Html)group.list.get(i)).IfType);
        jList2 = new javax.swing.JList();
        jList2.setListData(temp2);

so the strings description, index and Iftype is on the same line but not align and what I have just discovered is that the string length is the same for each string in the same column. Apparently, each character is not the same dimention(width).
0
Comment
Question by:ferrona
5 Comments
 
LVL 9

Expert Comment

by:Ovi
ID: 7161429
post some code
0
 
LVL 4

Expert Comment

by:kylar
ID: 7162554
Are you trying to align them to the left side or the right? If you're doing it to the right, write a custom Renderer that has a label that is right justified.. JList should left justify them automatically with the default renderer.

-K
0
 
LVL 92

Expert Comment

by:objects
ID: 7163714
Use a fixed width font for your list.
0
 
LVL 1

Accepted Solution

by:
wgilster earned 75 total points
ID: 7163920
Objects is right.  There are two types of fonts, fixed width and perportional.  Most likely your System.out is fixed and your list is perportional.
0
 
LVL 92

Expert Comment

by:objects
ID: 7166175
Hmmmmm
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java 8 lambda expresssions exception handling 3 75
Apps blocked by Java 9 64
xampp tool 12 30
how to install java on RHEL image on EC2 4 10
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now