Donnerstag, 15. November 2007

How to change the selectionColor of a JMenuItem

So you just created some colored JMenuItems, but you are unsatisfied, that everytime you move your mouse over the MenuItem, the nice color is changed to an ugly blue.

Use this MenuItemUI:

class myMenuItemUI extends BasicMenuItemUI{
public myMenuItemUI(Color c){
super();
this.selectionBackground = c;
}
}


Usage:
myMenuItem.setUI(new myMenuItemUI(Color.RED))

Montag, 5. November 2007

How to set the column width of a JTable?

If you want your JTable to display a fixed columnwidth which the user cannot change, you have to set the minWidth and the maxWidth of a column.

To set all columns to a fixed width of 10, use this code or modify it to your needs.



for (int i = 0; i < table.getColumnCount(); i++){ table.getColumn(table.getColumnName(i)).setMaxWidth(10); table.getColumn(table.getColumnName(i)).setMinWidth(10);
}