How to align strings in a swing.jList?

Posted on 2002-07-17
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) +
        jList2 = new javax.swing.JList();

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).
Question by:ferrona
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

Expert Comment

ID: 7161429
post some code

Expert Comment

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.

LVL 92

Expert Comment

ID: 7163714
Use a fixed width font for your list.

Accepted Solution

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.
LVL 92

Expert Comment

ID: 7166175

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 242
Custom Java Application connects to database: Which one of the 20? 4 44
ejb mdb examples 1 21
Netbeans and org.apache.commons.lang3 issue 3 31
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

696 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