We help IT Professionals succeed at work.

Add padding to table cell

dshrenik
dshrenik asked
on
Please let me know how I can add some padding at the left of a table cell. Thanks!
Comment
Watch Question

Awarded 2011
Awarded 2011
Commented:
seems like the code below worked for some guy:

http://www.java-forums.org/new-java/18428-how-do-you-add-cell-padding-jtable.html

public class MyColumnTableCellRenderer extends JLabel implements TableCellRenderer {
 
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, final int row, int column) {
 
               JLabel cellSpacingLabel= (JLabel) (this);
 
               if (hasFocus) {
                           setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
 
                           cellSpacingLabel=null;
               }
               else{
                           setBackground(table.getBackground());
              
                           stBorder(null);
 
 
                }
 
                if (isSelected) {    
 
 
                       setBackground(table.getSelectionBackground());
                 
                       setBorder(null);
 
 
               }
               else{
 
                       setBackground(table.getBackground());
                 
                       setBorder(null);
 
 
              }
 
                if (cellSpacingLabel != null) {
                          cellSpacingLabel .setBorder(new CompoundBorder(new EmptyBorder(new Insets(1, 4, 1, 4)), oLabel.getBorder()));
 
                }
 
 
                this.setOpaque(true);
                setText((String) value);
 
 
                 return this;
 
        }
 
 
 
}

Open in new window

Commented:
I guess it depends what sort of table - presumably your presentation layer, not a database layer.

Are we talking about swing, jpanel, ....?

Author

Commented:
I am taling about a JTable (Swing).

Author

Commented:
Another option is to add an empty icon.