Just nu i M3-nätverket
Jump to content

JTable


poppy

Recommended Posts

Hej!

 

Hur kan jag få texten i mina celler i tabellen att bli högerställd?

Detta är min kod:

 

leftTable = new JTable;

leftTable.setOpaque(false);

// Set the row height

leftTable.setRowHeight(RowHeight);

// Do not allow selection of rows leftTable.setRowSelectionAllowed(false);

// set column widths:

TableColumn col;

col=leftTable.getColumnModel().getColumn(0); col.setPreferredWidth(COLUMN_WIDTH_LEFT); col.setMaxWidth(COLUMN_WIDTH_LEFT); leftTable.setDefaultRenderer(Object.class, new ShadedTableCellRenderer());

 

...

 

class ShadedTableCellRenderer extends DefaultTableCellRenderer

{

public ShadedTableCellRenderer()

{

super();

}

public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)

{ Component component=super.getTableCellRendererComponent(table, value, isSelected, false, row, column);

if ( row ==14 || row ==13 || row ==12 || row==11)

{

component.setBackground(new Color(234, 249, 234));

}

else

{

component.setBackground(Color.white);

}

return component;

}

}

 

Tack på förhand

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...