I have a small program in which there is a tree and the "Change Look & Feel" button (there is nothing but a tree and this button). When the user clicks this button, a dialog box opens where you are prompted to select one of those available on the L & F system. On closing the dialog, Look & Feel is applied to the application. But there is such a problem: nodes in the tree are not updated from one L & F to another. In particular, this sometimes leads to the fact that the node does not have enough space for a new L & F and part of it is simply not visible.
This is cell renderer'a code:
class FileTreeCellRenderer implements TreeCellRenderer { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { JPanel panel = new JPanel(); JLabel label = new JLabel(); if (value instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value; Object object = treeNode.getUserObject(); if (object instanceof MyDocumentClass) { label.setText(((MyDocumentClass) object).getTitle()); } else { label.setText("package"); } label.setIcon(Icons.TREE_ITEM_ICON); panel.add(label); } return panel; } }
This is how I get available L & F:
UIManager.LookAndFeelInfo[] lf = UIManager.getInstalledLookAndFeels();
And this is how I apply the L & F chosen by the user:
try { UIManager.LookAndFeelInfo selected = (LookAndFeelItem) comboBox.getSelectedItem() UIManager.setLookAndFeel(selected.getClassName()); } catch (Throwable t) { t.printStackTrace(); }