tags:

views:

43

answers:

3

I am creating one application with billing facility, In that I want the amount column only display in the right alignment. Can anyone suggest me? Thanks in advance.

+1  A: 

See Concepts: Editors and Renderers, noting "Number — rendered by a right-aligned label." Just have your TableModel return the correct class. As a concrete example, note that Integer is a Number, while examining the implementation of getColumnClass() in this example.

trashgod
+1  A: 

You will require to get DefaultTableCellRenderer for table cells and call setHorizontalAlignment(alignment).

Example can be found on links :

http://articles.techrepublic.com.com/5100-10878_11-5032692.html

http://www.coderanch.com/t/337549/GUI/java/align-data-columns-JTable

YoK
@YoK: +1 I'm a little wary of articles that misspell `JTable`, but the sidebar show a complete example. :-)
trashgod
class RightTableCellRenderer extends DefaultTableCellRenderer { protected RightTableCellRenderer() { setHorizontalAlignment(JLabel.RIGHT); } i add this code, after that how can i set the renderer to my jtable column. }
Arivu2020
A: 

Try this:

JTable Tbl=new JTable(3,3){ 
          DefaultTableCellRenderer renderRight=new DefaultTableCellRenderer();

          {//initializer block
              renderRight.setHorizontalAlignment(SwingConstants.RIGHT);
          }

           @Override
        public TableCellRenderer getCellRenderer(int arg0, int arg1) {
               return renderRight;

        }

      };
Emil