Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to align strings in a swing.jList?

Posted on 2002-07-17
5
Medium Priority
?
1,251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 225 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This video teaches viewers about errors in exception handling.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

618 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