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(); } 

    1 answer 1

    Yes, this is a known issue. Unfortunately, sometimes the solution is to recreate the entire UI to apply the parameters. In other matters, not always. In your case, you did not notify the swing of the changes. This is done after installing L & F in this way:

     SwingUtilities.updateComponentTreeUI(frame); 

    Also, you may have to call pack () for a form or something like that to cause a layout recalculation.

    Read on this topic.

    http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html#dynamic

    • It turns out that to redraw all windows, it is necessary for all frame.getOwnedWindows () to do SwingUtilities.updateComponentTreeUI (ownedWindow); - angry