?
Solved

Text right-alignment in JTable

Posted on 2004-09-17
3
Medium Priority
?
462 Views
Last Modified: 2008-02-20
hi all

by default, the text/number in the grid in JTable are left-aligned.

How to make the text is left-alignment while number is right-alignment?

Rgds/Glogin
0
Comment
Question by:glogin
[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
  • 2
3 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12089938
use a custom cell renderer for the column.

DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setHorizontalAlignment(SwingConstants.RIGHT);
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 12091035
You need to use a custom TableCellRenderer. See

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#colorRenderer

and set the alignment as the second line of objects' code shows
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12122022
8-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 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