Code
JScrollPane scroll = new JScrollPane(table);
scroll.setColumnHeader(new JViewport() {
@Override public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
d.height = 32;
return d;
}
});
//or
table.setTableHeader(new JTableHeader(table.getColumnModel()) {
@Override public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
d.height = 32;
return d;
}
});
This comment has been removed by a blog administrator.
ReplyDeleteThe original message:
Delete> final TableCellRenderer tcrOs = myTable.getTableHeader().getDefaultRenderer();
> myTable.getTableHeader().setDefaultRenderer(new TableCellRenderer() {
> @Override
> public Component getTableCellRendererComponent(JTable table,
> Object value, boolean isSelected, boolean hasFocus,
> int row, int column) {
> JLabel lbl = (JLabel) tcrOs.getTableCellRendererComponent(table,
> value, isSelected, hasFocus, row, column);
> lbl.setForeground(AppVariables.textColor);
> lbl.setBorder(BorderFactory.createCompoundBorder(lbl.getBorder(),
> BorderFactory.createEmptyBorder(0, 5, 0, 0)));
> lbl.setHorizontalAlignment(SwingConstants.LEFT);
> if (isSelected) {
> lbl.setForeground(Color.red);
> lbl.setBackground(Color.lightGray);
> } else {
> lbl.setForeground(Color.blue);
> lbl.setBackground(Color.black);
> }
> return lbl;
> }
> });
> I have tried this code for JTable header for alignment. may be helpful for you.
I just removed the link. thanks.
@Fred, thanks for the info.
ReplyDeleteIf there is no possibility to change the Look and Feel, it's a simple way(NullPointerException occurs when you change the LnF).
This comment has been removed by the author.
ReplyDeletejava hello teacher, thank you for your contributions to all the world who want aprener over java, I want to ask something, is it possible to apply the rounded edge effect to a JComboBox? you can please post thank you very much
ReplyDelete@HANNIBAL T, Thank you for your request. I post Java Swing Tips: Rounded corner JComboBox border(Only tested BasicLookAndFeel, WindowsLookAndFeel).
ReplyDeleteAwesome.... its work. thanks
ReplyDeleteGlad to be of help :)
Delete