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

Cell alignment in JTable

Hi!

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

thanks
0
accarvajal
Asked:
accarvajal
  • 2
1 Solution
 
TrigunaCommented:
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
 
tienthinhCommented:
myJTable.getColumnNum(7).setRightAligned();
0
 
tienthinhCommented:
DefaultTableCellRenderer rend = new DefaultTableCellRenderer();
        rend.setHorizontalAlignment(JLabel.RIGHT);
        table.getColumnModel().getColumn(1).setCellRenderer(rend);
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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