А Б В Г Д Е Ж З И К Л М Н О П Р С Т У Ф Х Ц Ч Ш Э Ю Я Все примеры | Примеры по пакетам |
|
Таблица с раскрашенными столбцами
//Таблица с раскрашенными столбцами
package primery_java;
import javax.swing.*;
import java.awt.*;
import java.util.Vector;
import javax.swing.table.*;
public class TableColumnColored extends JFrame
{
public TableColumnColored ()
{
Vector row = new Vector();
Vector rows = new Vector();
row.add( "a1" );
row.add( "b1" );
row.add( "c1" );
rows.add( row );
row = new Vector();
row.add( "a2" );
row.add( "b2" );
row.add( "c2" );
rows.add( row );
Vector columns = new Vector();
columns.add ( "a" );
columns.add ( "b" );
columns.add ( "c" );
DefaultTableModel dtm = new DefaultTableModel(rows, columns);
JTable table=new JTable(dtm)
{
public Component prepareRenderer(TableCellRenderer renderer,
int row, int column)
{
Component component =
super.prepareRenderer(renderer,row,column);
if(column == 0)
{
component.setBackground(Color.yellow);
}
if(column == 1)
{
component.setBackground(Color.red);
}
if(column == 2)
{
component.setBackground(Color.cyan);
}
return component;
}
};
JScrollPane scroll=new JScrollPane(table);
this.setContentPane(scroll);
this.setBounds(100,50,300,150);
}
public static void main (String arg[])
{
TableColumnColored tcc = new TableColumnColored();
tcc.setVisible(true);
tcc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
|
|
|
|
|