?
Solved

Cell alignment in JTable

Posted on 2005-03-22
3
Medium Priority
?
3,663 Views
Last Modified: 2012-06-27
Hi!

I would like data in every JTable cell can be left, center o right aligned. How can I do this?

thanks
0
Comment
Question by:accarvajal
[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 5

Accepted Solution

by:
Triguna earned 80 total points
ID: 13608828
DefaultTableCellRenderer rend = new DefaultTableCellRenderer();
rend.setHorizontalAlignment(alignment);
t.getColumnModel().getColumn(col).setCellRenderer(rend);

Here your alignment may be JLabel.LEFT, JLabel.RIGHT.

t is any JTable object.

col is the column for which you want the alignment to be.
0
 

Expert Comment

by:tienthinh
ID: 26033833
myJTable.getColumnNum(7).setRightAligned();
0
 

Expert Comment

by:tienthinh
ID: 26033834
DefaultTableCellRenderer rend = new DefaultTableCellRenderer();
        rend.setHorizontalAlignment(JLabel.RIGHT);
        table.getColumnModel().getColumn(1).setCellRenderer(rend);
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

777 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