Solved

How to align strings in a swing.jList?

Posted on 2002-07-17
5
1,220 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
Comment Utility
post some code
0
 
LVL 4

Expert Comment

by:kylar
Comment Utility
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
Comment Utility
Use a fixed width font for your list.
0
 
LVL 1

Accepted Solution

by:
wgilster earned 75 total points
Comment Utility
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
Comment Utility
Hmmmmm
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

763 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

10 Experts available now in Live!

Get 1:1 Help Now