• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1261
  • Last Modified:

How to align strings in a swing.jList?

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
ferrona
Asked:
ferrona
1 Solution
 
OviCommented:
post some code
0
 
kylarCommented:
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
 
objectsCommented:
Use a fixed width font for your list.
0
 
wgilsterCommented:
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
 
objectsCommented:
Hmmmmm
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now