Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Swing / AWT / SWT
right justify text in a JTable
jeff willis
Greenhorn
Posts: 25
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Is it possible to right justify text in a JTable?
I've tried using Strings, JLabel, and even extending DefaultTableCellRenderer but all I ever get is left justified text.
Craig Wood
Ranch Hand
Posts: 1535
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.awt.*; import javax.swing.*; import javax.swing.table.*; public class AlignRight { public static void main(String[] args) { String[] headers = { "column 1", "column 2", "column 3", "column 4" }; int cols = 4; int rows = 6; String[][] data = new String[rows][cols]; for(int row = 0; row < rows; row++) for(int col = 0; col < cols; col++) data[row][col] = "item " + (row * cols + col + 1); JTable table = new JTable(data, headers); DefaultTableCellRenderer renderer = (DefaultTableCellRenderer)table.getDefaultRenderer(String.class); renderer.setHorizontalAlignment(JLabel.RIGHT); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(table)); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } }
jeff willis
Greenhorn
Posts: 25
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thanks. Your response is very impressive. Complete, to-the-point, and "cut-and-pastable"!
It's exactly what I needed.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
JTable tabbing
JTable Editing
jtable
Formatting JTable columns
Formatting JTable columns
More...