United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6453451 JTree is not visible with GTK and Right-to-Left component orientation
JDK-6453451 : JTree is not visible with GTK and Right-to-Left component orientation

Details
Type:
Bug
Submit Date:
2006-07-27
Status:
Closed
Updated Date:
2011-03-07
Project Name:
JDK
Resolved Date:
2011-03-07
Component:
client-libs
OS:
solaris,generic
Sub-Component:
javax.swing
CPU:
sparc,generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Backport:
Duplicate:

Sub Tasks

Description
FULL PRODUCT VERSION :
Mustang b91

A DESCRIPTION OF THE PROBLEM :
JTree is invisible with combination of Right-to-Left component orientation and GTK LaF.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run. You don't see the JTree. Notice that with commented out "scroll.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);" it works ok. It works ok as well with the uncommented "ComponentOrientation.RIGHT_TO_LEFT" code but with another LaF, say Motif.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JTree displays.
ACTUAL -
JTree does not display.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.lang.reflect.InvocationTargetException;

public class GTKTreeRTLTest {
    
    private static JFrame mainFrame;
    
    public static void main(String[] args) throws InterruptedException, InvocationTargetException {
        SwingUtilities.invokeAndWait(new Runnable(){
            
            public void run() {
                mainFrame = new JFrame("GTKTreeRTLTest");
                mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                try {
                    // ???
                    UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
//                    UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
                    
                    SwingUtilities.updateComponentTreeUI(mainFrame);
                } catch (Exception e) {
                    throw new RuntimeException("Test failed: ", e);
                }
                
                JTree tree = new JTree(getDefaultTreeModel());
                tree.setShowsRootHandles(true);
                tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
                JPanel mainPanel = new JPanel(new BorderLayout());
                JScrollPane scroll = new JScrollPane(tree);
                mainPanel.add(scroll, BorderLayout.CENTER);
                mainFrame.setContentPane(mainPanel);
                
                // ???
                scroll.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
                
                mainFrame.pack();
                mainFrame.setLocationRelativeTo(null);
                mainFrame.setVisible(true);
            }
        
        });
        
        mainFrame.validate();
    }
    
    private static DefaultTreeModel getDefaultTreeModel() {
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("JTree");
        DefaultMutableTreeNode parent;

        parent = new DefaultMutableTreeNode("colors");
        root.add(parent);
        parent.add(new DefaultMutableTreeNode("blue"));
        parent.add(new DefaultMutableTreeNode("violet"));
        parent.add(new DefaultMutableTreeNode("red"));
        parent.add(new DefaultMutableTreeNode("yellow"));

        parent = new DefaultMutableTreeNode("sports");
        root.add(parent);
        parent.add(new DefaultMutableTreeNode("basketball"));
        parent.add(new DefaultMutableTreeNode("soccer"));
        parent.add(new DefaultMutableTreeNode("football"));

        DefaultMutableTreeNode nparent = new DefaultMutableTreeNode("hockey");
        parent.add(nparent);
        nparent.add(new DefaultMutableTreeNode("ice hockey"));
        nparent.add(new DefaultMutableTreeNode("roller hockey"));
        nparent.add(new DefaultMutableTreeNode("floor hockey"));
        nparent.add(new DefaultMutableTreeNode("road hockey"));

        return new DefaultTreeModel(root);
    }
    
}

---------- END SOURCE ----------

                                    

Comments
EVALUATION

BasicTreeUI and BasicListUI make cached copies of several component properties, like isLeftToRight and width. Those copies are updated by code in several random places that does not necessarily get invoked from Synth UI classes. E.g. tree width is updated in BasicTreeUI.paint() which is overridden in SynthTreeUI.

The solution is to nuke these cached copies and retrieve properties directly from components.
                                     
2006-08-09
EVALUATION

For testing, I attached TreeTest.java.

1.4.2 - it works fine under GTK L&F with RTL.
5.0 - JTree shows something when you switch to GTK RTL.
      But there is an issue with positioning. Try resizing the window.
6.0 - Same is 1.5
                                     
2006-08-14
SUGGESTED FIX

http://javaweb.sfbay/jcg/1.7.0-dolphin/swing/6453451/
                                     
2006-09-19



Hardware and Software, Engineered to Work Together