swingx
  1. swingx
  2. SWINGX-1538

ClassCastException when Collapsible Pane content extends certain classes

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.6.4
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      Java SE 6 and 7

      Description

      When certain components are set as the content for a JXCollapsiblePane, and somethimes only under certain Look&Feel's, a ClassCastException is thrown when trying to paint the border for the component:

      • Any class that extends AbstractButton under Nimbus or Metal
      • JSplitPane under any Look&Feel
      • JXTaskPane under any Look&Feel
        Also this problem doesn't get triggered always but I'm not able to isolate the concrete circumstances, neither the trace seems representative to me. I've attached a program that allows the test of this scenario with several components.
        There's an easy workaround which is using the content pane provided or simply setting any JPanel, so is not an stuck problem, but I think it's better to report as it might have some collateral effects.

        Activity

        Hide
        dsmania added a comment - - edited

        Since I'm not able to attach files (or I am blind to see where the option is) here's the code for the test:

        CollapsiblePaneContentTest.java
        import java.awt.Component;
        import java.awt.Dimension;
        import java.awt.Image;
        import java.awt.event.ActionEvent;
        import java.awt.event.ItemEvent;
        import java.awt.event.ItemListener;
        import java.beans.PropertyChangeEvent;
        import java.beans.PropertyChangeListener;
        import java.net.URL;
        import java.util.Arrays;
        import java.util.Calendar;
        import java.util.Hashtable;
        import javax.swing.*;
        import javax.swing.tree.DefaultMutableTreeNode;
        import org.jdesktop.swingx.*;
        import org.jdesktop.swingx.action.AbstractActionExt;
        import org.jdesktop.swingx.painter.CheckerboardPainter;
        import org.jdesktop.swingx.tips.DefaultTipOfTheDayModel;
        import org.jdesktop.swingx.tips.TipOfTheDayModel;
        import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
        import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
        import org.jdesktop.swingx.treetable.TreeTableModel;
        
        public class CollapsiblePaneContentTest extends JXPanel {
        
            private static final long serialVersionUID = 1L;
        
            public CollapsiblePaneContentTest() {
                super(new VerticalLayout());
                super.setBackgroundPainter(new CheckerboardPainter());
        
                final JXCollapsiblePane collapsiblePane = new JXCollapsiblePane();
                collapsiblePane.setCollapsed(false);
        
                final JXComboBox componentsCombo = new JXComboBox(new JComponent[] {
                        new JButton("A button"),
                        new JCheckBox("A check box"),
                        new JComboBox(new String[] { "A combo box", "is what", "this is" }),
                        new JColorChooser(),
                        newJDesktopPane(),
                        new JEditorPane("text/html", "<html>An <b>editor pane</b></html>"),
                        new JFormattedTextField("A formatted text field"),
                        new JLabel("A label"),
                        new JList(new String[] { "A list", "is what", "this is" }),
                        new JOptionPane("An option pane", JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION),
                        new JPanel(),
                        new JProgressBar(new DefaultBoundedRangeModel(50, 10, 0, 100)),
                        new JRadioButton("A radio button"),
                        new JScrollPane(new JXLabel("A scroll pane")),
                        new JSeparator(),
                        newJSlider(),
                        new JSpinner(new SpinnerListModel(new String[] { "A spiner", "is what", "this is" })),
                        new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, new JLabel("A split pane"),
                                new JLabel("A split pane")),
                        newJTabbedPane(),
                        new JTable(new String[][] { new String[] { "A", "table" }, new String[] { "is", "what" },
                                new String[] { "this", "is" } }, new String[] { "A", "B" }),
                        new JTextArea("A text area"),
                        new JTextField("A text field"),
                        new JToggleButton("A toggle button"),
                        new JTree(newTreeModelRoot()),
        
                        new JXBusyLabel(),
                        new JXButton("A button"),
                        new JXColorSelectionButton(),
                        new JXComboBox(new String[] { "A combo box", "is what", "this is" }),
                        new JXDatePicker(Calendar.getInstance().getTime()),
                        new JXEditorPane("text/html", "<html>An <b>editor pane</b></html>"),
                        new JXErrorPane(),
                        new JXFindBar(),
                        new JXFindPanel(),
                        new JXFormattedTextField("A formatted text field"),
                        new JXGradientChooser(),
                        new JXGraph(),
                        new JXHeader("A header", "is what this is"),
                        new JXHyperlink(new AbstractActionExt("An hyperlink") { private static final long serialVersionUID = 1L;
                                @Override public void actionPerformed(ActionEvent e) { /* */ }}),
                        newJXImageView(),
                        new JXLabel("A label"),
                        new JXList(new String[] { "A list", "is what", "this is" }),
                        new JXLoginPane(),
                        new JXMonthView(),
                        newJXMultiSplitPane(),
                        new JXMultiThumbSlider<Object>(),
                        new JXPanel(),
                        new JXSearchField("A search field"),
                        new JXSearchPanel(),
                        new JXRadioGroup<String>(new String[] { "A", "radio", "group" }),
                        new JXTaskPane("A task pane"),
                        newJXTaskPaneContainer(),
                        new JXTable(new String[][] { new String[] { "A", "table" }, new String[] { "is", "what" },
                                new String[] { "this", "is" } }, new String[] { "A", "B" }),
                        new JXTextArea("A text area"),
                        new JXTextField("A text field"),
                        new JXTipOfTheDay(newTipOfTheDayModel()),
                        new JXTitledPanel("A titled panel"),
                        new JXTitledSeparator("A titled separator"),
                        new JXTree(newTreeModelRoot()),
                        new JXTreeTable(newTreeTableModel()),
                });
                componentsCombo.setRenderer(new DefaultListCellRenderer() {
                    private static final long serialVersionUID = 1L;
                    @Override
                    public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected,
                            boolean focused) {
                        DefaultListCellRenderer component = (DefaultListCellRenderer) super.getListCellRendererComponent(list,
                                value, index, selected, focused);
                        component.setText(value.getClass().getSimpleName());
        
                        return component;
                    }});
                componentsCombo.addItemListener(new ItemListener() {
                    @Override
                    public void itemStateChanged(ItemEvent event) {
                        collapsiblePane.setCollapsed(true);
                        collapsiblePane.setContentPane((JComponent) event.getItem());
                        collapsiblePane.setCollapsed(false);
                    }});
        
                collapsiblePane.setContentPane((JComponent) componentsCombo.getItemAt(0));
        
                Action reproduceExceptionAction = new AbstractActionExt("<html>Reproduce exception:<br /><ol>" +
                        "<li>Set an AbstractButton as content</li>" +
                		"<li>Set Nimbus look and feel</li>" +
                		"<li>Toggle</li></ol></html>") {
                    private static final long serialVersionUID = 1L;
                    @Override
                    @SuppressWarnings("unchecked")
                    public void actionPerformed(ActionEvent event) {
                        LookAndFeel nimbus = null;
                        for (UIManager.LookAndFeelInfo lafInfo : UIManager.getInstalledLookAndFeels()) {
                            if (lafInfo.getName() == "Nimbus") {
                                try {
                                    nimbus = ((Class<LookAndFeel>) Class.forName(lafInfo.getClassName())).newInstance();
                                } catch (Exception e) {
                                    JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(
                                            CollapsiblePaneContentTest.this), "This shouldn't be happening.",
                                            "Unexpected error", JOptionPane.ERROR_MESSAGE);
                                    e.printStackTrace();
                                }
                            }
                        }
        
                        if (nimbus != null) {
                            int i = 0;
                            AbstractButton button = null;
                            while ((i < componentsCombo.getItemCount()) && (button == null)) {
                                Object item = componentsCombo.getItemAt(i);
                                if (item instanceof AbstractButton) {
                                    button = (AbstractButton) item;
                                }
                                i++;
                            }
                            if (button != null) {
                                componentsCombo.setSelectedItem(button);
        
                                try {
                                    UIManager.setLookAndFeel(nimbus);
                                } catch (UnsupportedLookAndFeelException e) {
                                    JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(
                                            CollapsiblePaneContentTest.this), "This shouldn't be happening.",
                                            "Unexpected error", JOptionPane.ERROR_MESSAGE);
                                    e.printStackTrace();
                                }
                                SwingUtilities.updateComponentTreeUI(SwingUtilities.getWindowAncestor(
                                        CollapsiblePaneContentTest.this));
        
                                collapsiblePane.setCollapsed(false);
                                collapsiblePane.setCollapsed(true);
                            } else {
                                JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(CollapsiblePaneContentTest.this),
                                        "There is no " + AbstractButton.class.getSimpleName() + " in the combo, you can't"
                                        + " reproduce this exception properly.", "Content error", JOptionPane.ERROR_MESSAGE);
                                setEnabled(false);
                            }
                        } else {
                            JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(CollapsiblePaneContentTest.this),
                                    "Your system does not support Nimbus, you can't reproduce this exception properly.",
                                    "Look and Feel error", JOptionPane.ERROR_MESSAGE);
                            setEnabled(false);
                        }
                    }};
        
                add(new JXButton(reproduceExceptionAction));
                add(componentsCombo);
                add(collapsiblePane);
                add(new JXButton(collapsiblePane.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION)));
            }
        
            protected static Action createChangeLookAndFeelAction(final JFrame frame, final UIManager.LookAndFeelInfo lookAndFeelInfo) {
                return new AbstractActionExt(lookAndFeelInfo.getName()) {
                    private static final long serialVersionUID = 1L;
                    @Override
                    public void actionPerformed(ActionEvent event) {
                        try {
                            UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());
                            SwingUtilities.updateComponentTreeUI(frame);
                        } catch (Exception e) {
                            JOptionPane.showMessageDialog(frame, "There was a problem setting the look and feel "
                                    + lookAndFeelInfo.getName() + ".", "Look and Feel error", JOptionPane.ERROR_MESSAGE);
                            e.printStackTrace();
                        }
                    }};
            }
        
            protected static JDesktopPane newJDesktopPane() {
                JDesktopPane desktopPane = new JDesktopPane();
                desktopPane.setPreferredSize(new Dimension(800, 400));
        
                JInternalFrame internalFrame = new JInternalFrame("An internal frame");
                internalFrame.setSize(new Dimension(150, 50));
                internalFrame.getContentPane().add(new JLabel("inside a desktop pane"));
                internalFrame.setVisible(true);
                desktopPane.add(internalFrame);
        
                return desktopPane;
            }
        
            protected static JSlider newJSlider() {
                JSlider slider = new JSlider(0, 7);
                Hashtable<Integer, JComponent> labelTable = new Hashtable<Integer, JComponent>();
                labelTable.put(Integer.valueOf(0), new JXLabel("A"));
                labelTable.put(Integer.valueOf(1), new JXLabel(" "));
                labelTable.put(Integer.valueOf(2), new JXLabel("S"));
                labelTable.put(Integer.valueOf(3), new JXLabel("l"));
                labelTable.put(Integer.valueOf(4), new JXLabel("i"));
                labelTable.put(Integer.valueOf(5), new JXLabel("d"));
                labelTable.put(Integer.valueOf(6), new JXLabel("e"));
                labelTable.put(Integer.valueOf(7), new JXLabel("r"));
                slider.setLabelTable(labelTable);
                slider.setPaintLabels(true);
                slider.setPaintTicks(true);
                slider.setSnapToTicks(true);
                slider.getModel();
        
                return slider;
            }
        
            protected static JTabbedPane newJTabbedPane() {
                JTabbedPane tabbedPane = new JTabbedPane();
                tabbedPane.addTab("A", new JXLabel("A tabbed pane"));
                tabbedPane.addTab("tabbed", new JXLabel("A tabbed pane"));
                tabbedPane.addTab("pane", new JXLabel("A tabbed pane"));
        
                return tabbedPane;
            }
        
            protected static JXImageView newJXImageView() {
                JXImageView imageView = new JXImageView();
                try {
                    imageView.setImage(new URL("http://duke.kenai.com/wave/Wave.jpg"));
                    Image image = imageView.getImage();
                    if (image != null) {
                        imageView.setPreferredSize(new Dimension(image.getWidth(imageView), image.getHeight(imageView)));
                    }
                } catch (Exception e) {
                    // Ignored
                }
        
                return imageView;
            }
        
            protected static JXMultiSplitPane newJXMultiSplitPane() {
                JXMultiSplitPane multiSplitPane = new JXMultiSplitPane(new MultiSplitLayout(MultiSplitLayout.parseModel(
                        "(COLUMN (ROW (LEAF name=NW weight=0.5) (LEAF name=NE weight=0.5))"
                        + " (ROW (LEAF name=SW weight=0.5) (LEAF name=SE weight=0.5)))")));
                multiSplitPane.add(new JXLabel("A"), "NW");
                multiSplitPane.add(new JXLabel("multi"), "NE");
                multiSplitPane.add(new JXLabel("split"), "SW");
                multiSplitPane.add(new JXLabel("pane"), "SE");
        
                return multiSplitPane;
            }
        
            protected static JXTaskPaneContainer newJXTaskPaneContainer() {
                JXTaskPaneContainer taskPaneContainer = new JXTaskPaneContainer();
                taskPaneContainer.add(new JXTaskPane("A"));
                taskPaneContainer.add(new JXTaskPane("task"));
                taskPaneContainer.add(new JXTaskPane("pane"));
                taskPaneContainer.add(new JXTaskPane("container"));
        
                return taskPaneContainer;
            }
        
            protected static TipOfTheDayModel newTipOfTheDayModel() {
                return new DefaultTipOfTheDayModel(new TipOfTheDayModel.Tip[] { new TipOfTheDayModel.Tip() {
                    @Override
                    public String getTipName() {
                        return "Tip of the Day";
                    }
                    @Override
                    public Object getTip() {
                        return "This is a Tip of the Day.";
                    }} });
            }
        
            protected static DefaultMutableTreeNode newTreeModelRoot() {
                DefaultMutableTreeNode root = new DefaultMutableTreeNode("A tree");
                DefaultMutableTreeNode isNode = new DefaultMutableTreeNode("is");
                DefaultMutableTreeNode whatNode = new DefaultMutableTreeNode("what");
                DefaultMutableTreeNode thisNode = new DefaultMutableTreeNode("this");
                DefaultMutableTreeNode is2Node = new DefaultMutableTreeNode("is");
                root.add(isNode);
                isNode.add(whatNode);
                root.add(thisNode);
                thisNode.add(is2Node);
        
                return root;
            }
        
            protected static TreeTableModel newTreeTableModel() {
                DefaultMutableTreeTableNode root = createDefaultMutableTreeTableNode(null);
                DefaultMutableTreeTableNode aTreeNode = createDefaultMutableTreeTableNode("A tree table");
                DefaultMutableTreeTableNode isNode = createDefaultMutableTreeTableNode("is");
                DefaultMutableTreeTableNode whatNode = createDefaultMutableTreeTableNode("what");
                DefaultMutableTreeTableNode thisNode = createDefaultMutableTreeTableNode("this");
                DefaultMutableTreeTableNode is2Node = createDefaultMutableTreeTableNode("is");
                root.add(aTreeNode);
                aTreeNode.add(isNode);
                isNode.add(whatNode);
                aTreeNode.add(thisNode);
                thisNode.add(is2Node);
        
                return new DefaultTreeTableModel(root, Arrays.asList("Hierarchical", "Plain"));
            }
        
            private static DefaultMutableTreeTableNode createDefaultMutableTreeTableNode(Object userObject) {
                return new DefaultMutableTreeTableNode(userObject) {
                    @Override
                    public int getColumnCount() {
                        return 2;
                    }};
            }
        
            public static void main(String... args) {
                JFrame.setDefaultLookAndFeelDecorated(false);
                JDialog.setDefaultLookAndFeelDecorated(false);
        
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (Exception e) {
                    e.printStackTrace();
                }
        
                CollapsiblePaneContentTest collapsiblePaneOpacityTest = new CollapsiblePaneContentTest();
        
                final JXFrame frame = new JXFrame(CollapsiblePaneContentTest.class.getSimpleName());
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setStartPosition(JXFrame.StartPosition.CenterInScreen);
                frame.setPreferredSize(new Dimension(800, 600));
                frame.setContentPane(collapsiblePaneOpacityTest);
        
                Action closeFrameAction = new AbstractActionExt("Exit") {
                    private static final long serialVersionUID = 1L;
                    @Override
                    public void actionPerformed(ActionEvent event) {
                        frame.dispose();
                    }};
        
                JMenuBar menuBar = new JMenuBar();
                JMenu fileMenu = new JMenu("File");
                fileMenu.add(new JMenuItem(closeFrameAction));
                menuBar.add(fileMenu);
                JMenu lookAndFeelMenu = new JMenu("Look&Feel");
                for (UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels()) {
                    lookAndFeelMenu.add(new JMenuItem(createChangeLookAndFeelAction(frame, lookAndFeelInfo)));
                }
                menuBar.add(lookAndFeelMenu);
                frame.setJMenuBar(menuBar);
        
                JXStatusBar statusBar = new JXStatusBar();
                final JXLabel lookAndFeelLabel = new JXLabel(UIManager.getLookAndFeel().getName());
                statusBar.add(lookAndFeelLabel);
                statusBar.add(lookAndFeelLabel);
                UIManager.addPropertyChangeListener(new PropertyChangeListener() {
                    @Override
                    public void propertyChange(PropertyChangeEvent event) {
                        if (event.getPropertyName() == "lookAndFeel") {
                            lookAndFeelLabel.setText(((LookAndFeel) event.getNewValue()).getName());
                        }
                    }});
                frame.setStatusBar(statusBar);
        
                frame.pack();
                frame.setVisible(true);
            }
        
        }
        
        Show
        dsmania added a comment - - edited Since I'm not able to attach files (or I am blind to see where the option is) here's the code for the test: CollapsiblePaneContentTest.java import java.awt.Component; import java.awt.Dimension; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.net.URL; import java.util.Arrays; import java.util.Calendar; import java.util.Hashtable; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import org.jdesktop.swingx.*; import org.jdesktop.swingx.action.AbstractActionExt; import org.jdesktop.swingx.painter.CheckerboardPainter; import org.jdesktop.swingx.tips.DefaultTipOfTheDayModel; import org.jdesktop.swingx.tips.TipOfTheDayModel; import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; import org.jdesktop.swingx.treetable.DefaultTreeTableModel; import org.jdesktop.swingx.treetable.TreeTableModel; public class CollapsiblePaneContentTest extends JXPanel { private static final long serialVersionUID = 1L; public CollapsiblePaneContentTest() { super ( new VerticalLayout()); super .setBackgroundPainter( new CheckerboardPainter()); final JXCollapsiblePane collapsiblePane = new JXCollapsiblePane(); collapsiblePane.setCollapsed( false ); final JXComboBox componentsCombo = new JXComboBox( new JComponent[] { new JButton( "A button" ), new JCheckBox( "A check box" ), new JComboBox( new String [] { "A combo box" , "is what" , " this is" }), new JColorChooser(), newJDesktopPane(), new JEditorPane( "text/html" , "<html>An <b>editor pane</b></html>" ), new JFormattedTextField( "A formatted text field" ), new JLabel( "A label" ), new JList( new String [] { "A list" , "is what" , " this is" }), new JOptionPane( "An option pane" , JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION), new JPanel(), new JProgressBar( new DefaultBoundedRangeModel(50, 10, 0, 100)), new JRadioButton( "A radio button" ), new JScrollPane( new JXLabel( "A scroll pane" )), new JSeparator(), newJSlider(), new JSpinner( new SpinnerListModel( new String [] { "A spiner" , "is what" , " this is" })), new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true , new JLabel( "A split pane" ), new JLabel( "A split pane" )), newJTabbedPane(), new JTable( new String [][] { new String [] { "A" , "table" }, new String [] { "is" , "what" }, new String [] { " this " , "is" } }, new String [] { "A" , "B" }), new JTextArea( "A text area" ), new JTextField( "A text field" ), new JToggleButton( "A toggle button" ), new JTree(newTreeModelRoot()), new JXBusyLabel(), new JXButton( "A button" ), new JXColorSelectionButton(), new JXComboBox( new String [] { "A combo box" , "is what" , " this is" }), new JXDatePicker(Calendar.getInstance().getTime()), new JXEditorPane( "text/html" , "<html>An <b>editor pane</b></html>" ), new JXErrorPane(), new JXFindBar(), new JXFindPanel(), new JXFormattedTextField( "A formatted text field" ), new JXGradientChooser(), new JXGraph(), new JXHeader( "A header" , "is what this is" ), new JXHyperlink( new AbstractActionExt( "An hyperlink" ) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { /* */ }}), newJXImageView(), new JXLabel( "A label" ), new JXList( new String [] { "A list" , "is what" , " this is" }), new JXLoginPane(), new JXMonthView(), newJXMultiSplitPane(), new JXMultiThumbSlider< Object >(), new JXPanel(), new JXSearchField( "A search field" ), new JXSearchPanel(), new JXRadioGroup< String >( new String [] { "A" , "radio" , "group" }), new JXTaskPane( "A task pane" ), newJXTaskPaneContainer(), new JXTable( new String [][] { new String [] { "A" , "table" }, new String [] { "is" , "what" }, new String [] { " this " , "is" } }, new String [] { "A" , "B" }), new JXTextArea( "A text area" ), new JXTextField( "A text field" ), new JXTipOfTheDay(newTipOfTheDayModel()), new JXTitledPanel( "A titled panel" ), new JXTitledSeparator( "A titled separator" ), new JXTree(newTreeModelRoot()), new JXTreeTable(newTreeTableModel()), }); componentsCombo.setRenderer( new DefaultListCellRenderer() { private static final long serialVersionUID = 1L; @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected, boolean focused) { DefaultListCellRenderer component = (DefaultListCellRenderer) super .getListCellRendererComponent(list, value, index, selected, focused); component.setText(value.getClass().getSimpleName()); return component; }}); componentsCombo.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent event) { collapsiblePane.setCollapsed( true ); collapsiblePane.setContentPane((JComponent) event.getItem()); collapsiblePane.setCollapsed( false ); }}); collapsiblePane.setContentPane((JComponent) componentsCombo.getItemAt(0)); Action reproduceExceptionAction = new AbstractActionExt( "<html>Reproduce exception:<br /><ol>" + "<li>Set an AbstractButton as content</li>" + "<li>Set Nimbus look and feel</li>" + "<li>Toggle</li></ol></html>" ) { private static final long serialVersionUID = 1L; @Override @SuppressWarnings( "unchecked" ) public void actionPerformed(ActionEvent event) { LookAndFeel nimbus = null ; for (UIManager.LookAndFeelInfo lafInfo : UIManager.getInstalledLookAndFeels()) { if (lafInfo.getName() == "Nimbus" ) { try { nimbus = (( Class <LookAndFeel>) Class .forName(lafInfo.getClassName())).newInstance(); } catch (Exception e) { JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor( CollapsiblePaneContentTest. this ), "This shouldn't be happening." , "Unexpected error" , JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } } } if (nimbus != null ) { int i = 0; AbstractButton button = null ; while ((i < componentsCombo.getItemCount()) && (button == null )) { Object item = componentsCombo.getItemAt(i); if (item instanceof AbstractButton) { button = (AbstractButton) item; } i++; } if (button != null ) { componentsCombo.setSelectedItem(button); try { UIManager.setLookAndFeel(nimbus); } catch (UnsupportedLookAndFeelException e) { JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor( CollapsiblePaneContentTest. this ), "This shouldn't be happening." , "Unexpected error" , JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } SwingUtilities.updateComponentTreeUI(SwingUtilities.getWindowAncestor( CollapsiblePaneContentTest. this )); collapsiblePane.setCollapsed( false ); collapsiblePane.setCollapsed( true ); } else { JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(CollapsiblePaneContentTest. this ), "There is no " + AbstractButton.class.getSimpleName() + " in the combo, you can't" + " reproduce this exception properly." , "Content error" , JOptionPane.ERROR_MESSAGE); setEnabled( false ); } } else { JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(CollapsiblePaneContentTest. this ), "Your system does not support Nimbus, you can't reproduce this exception properly." , "Look and Feel error" , JOptionPane.ERROR_MESSAGE); setEnabled( false ); } }}; add( new JXButton(reproduceExceptionAction)); add(componentsCombo); add(collapsiblePane); add( new JXButton(collapsiblePane.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION))); } protected static Action createChangeLookAndFeelAction( final JFrame frame, final UIManager.LookAndFeelInfo lookAndFeelInfo) { return new AbstractActionExt(lookAndFeelInfo.getName()) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { try { UIManager.setLookAndFeel(lookAndFeelInfo.getClassName()); SwingUtilities.updateComponentTreeUI(frame); } catch (Exception e) { JOptionPane.showMessageDialog(frame, "There was a problem setting the look and feel " + lookAndFeelInfo.getName() + "." , "Look and Feel error" , JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } }}; } protected static JDesktopPane newJDesktopPane() { JDesktopPane desktopPane = new JDesktopPane(); desktopPane.setPreferredSize( new Dimension(800, 400)); JInternalFrame internalFrame = new JInternalFrame( "An internal frame" ); internalFrame.setSize( new Dimension(150, 50)); internalFrame.getContentPane().add( new JLabel( "inside a desktop pane" )); internalFrame.setVisible( true ); desktopPane.add(internalFrame); return desktopPane; } protected static JSlider newJSlider() { JSlider slider = new JSlider(0, 7); Hashtable< Integer , JComponent> labelTable = new Hashtable< Integer , JComponent>(); labelTable.put( Integer .valueOf(0), new JXLabel( "A" )); labelTable.put( Integer .valueOf(1), new JXLabel( " " )); labelTable.put( Integer .valueOf(2), new JXLabel( "S" )); labelTable.put( Integer .valueOf(3), new JXLabel( "l" )); labelTable.put( Integer .valueOf(4), new JXLabel( "i" )); labelTable.put( Integer .valueOf(5), new JXLabel( "d" )); labelTable.put( Integer .valueOf(6), new JXLabel( "e" )); labelTable.put( Integer .valueOf(7), new JXLabel( "r" )); slider.setLabelTable(labelTable); slider.setPaintLabels( true ); slider.setPaintTicks( true ); slider.setSnapToTicks( true ); slider.getModel(); return slider; } protected static JTabbedPane newJTabbedPane() { JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab( "A" , new JXLabel( "A tabbed pane" )); tabbedPane.addTab( "tabbed" , new JXLabel( "A tabbed pane" )); tabbedPane.addTab( "pane" , new JXLabel( "A tabbed pane" )); return tabbedPane; } protected static JXImageView newJXImageView() { JXImageView imageView = new JXImageView(); try { imageView.setImage( new URL( "http: //duke.kenai.com/wave/Wave.jpg" )); Image image = imageView.getImage(); if (image != null ) { imageView.setPreferredSize( new Dimension(image.getWidth(imageView), image.getHeight(imageView))); } } catch (Exception e) { // Ignored } return imageView; } protected static JXMultiSplitPane newJXMultiSplitPane() { JXMultiSplitPane multiSplitPane = new JXMultiSplitPane( new MultiSplitLayout(MultiSplitLayout.parseModel( "(COLUMN (ROW (LEAF name=NW weight=0.5) (LEAF name=NE weight=0.5))" + " (ROW (LEAF name=SW weight=0.5) (LEAF name=SE weight=0.5)))" ))); multiSplitPane.add( new JXLabel( "A" ), "NW" ); multiSplitPane.add( new JXLabel( "multi" ), "NE" ); multiSplitPane.add( new JXLabel( "split" ), "SW" ); multiSplitPane.add( new JXLabel( "pane" ), "SE" ); return multiSplitPane; } protected static JXTaskPaneContainer newJXTaskPaneContainer() { JXTaskPaneContainer taskPaneContainer = new JXTaskPaneContainer(); taskPaneContainer.add( new JXTaskPane( "A" )); taskPaneContainer.add( new JXTaskPane( "task" )); taskPaneContainer.add( new JXTaskPane( "pane" )); taskPaneContainer.add( new JXTaskPane( "container" )); return taskPaneContainer; } protected static TipOfTheDayModel newTipOfTheDayModel() { return new DefaultTipOfTheDayModel( new TipOfTheDayModel.Tip[] { new TipOfTheDayModel.Tip() { @Override public String getTipName() { return "Tip of the Day" ; } @Override public Object getTip() { return "This is a Tip of the Day." ; }} }); } protected static DefaultMutableTreeNode newTreeModelRoot() { DefaultMutableTreeNode root = new DefaultMutableTreeNode( "A tree" ); DefaultMutableTreeNode isNode = new DefaultMutableTreeNode( "is" ); DefaultMutableTreeNode whatNode = new DefaultMutableTreeNode( "what" ); DefaultMutableTreeNode thisNode = new DefaultMutableTreeNode( " this " ); DefaultMutableTreeNode is2Node = new DefaultMutableTreeNode( "is" ); root.add(isNode); isNode.add(whatNode); root.add(thisNode); thisNode.add(is2Node); return root; } protected static TreeTableModel newTreeTableModel() { DefaultMutableTreeTableNode root = createDefaultMutableTreeTableNode( null ); DefaultMutableTreeTableNode aTreeNode = createDefaultMutableTreeTableNode( "A tree table" ); DefaultMutableTreeTableNode isNode = createDefaultMutableTreeTableNode( "is" ); DefaultMutableTreeTableNode whatNode = createDefaultMutableTreeTableNode( "what" ); DefaultMutableTreeTableNode thisNode = createDefaultMutableTreeTableNode( " this " ); DefaultMutableTreeTableNode is2Node = createDefaultMutableTreeTableNode( "is" ); root.add(aTreeNode); aTreeNode.add(isNode); isNode.add(whatNode); aTreeNode.add(thisNode); thisNode.add(is2Node); return new DefaultTreeTableModel(root, Arrays.asList( "Hierarchical" , "Plain" )); } private static DefaultMutableTreeTableNode createDefaultMutableTreeTableNode( Object userObject) { return new DefaultMutableTreeTableNode(userObject) { @Override public int getColumnCount() { return 2; }}; } public static void main( String ... args) { JFrame.setDefaultLookAndFeelDecorated( false ); JDialog.setDefaultLookAndFeelDecorated( false ); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } CollapsiblePaneContentTest collapsiblePaneOpacityTest = new CollapsiblePaneContentTest(); final JXFrame frame = new JXFrame(CollapsiblePaneContentTest.class.getSimpleName()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setStartPosition(JXFrame.StartPosition.CenterInScreen); frame.setPreferredSize( new Dimension(800, 600)); frame.setContentPane(collapsiblePaneOpacityTest); Action closeFrameAction = new AbstractActionExt( "Exit" ) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { frame.dispose(); }}; JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu( "File" ); fileMenu.add( new JMenuItem(closeFrameAction)); menuBar.add(fileMenu); JMenu lookAndFeelMenu = new JMenu( "Look&Feel" ); for (UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels()) { lookAndFeelMenu.add( new JMenuItem(createChangeLookAndFeelAction(frame, lookAndFeelInfo))); } menuBar.add(lookAndFeelMenu); frame.setJMenuBar(menuBar); JXStatusBar statusBar = new JXStatusBar(); final JXLabel lookAndFeelLabel = new JXLabel(UIManager.getLookAndFeel().getName()); statusBar.add(lookAndFeelLabel); statusBar.add(lookAndFeelLabel); UIManager.addPropertyChangeListener( new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { if (event.getPropertyName() == "lookAndFeel" ) { lookAndFeelLabel.setText(((LookAndFeel) event.getNewValue()).getName()); } }}); frame.setStatusBar(statusBar); frame.pack(); frame.setVisible( true ); } }

          People

          • Assignee:
            Karl Schaefer
            Reporter:
            dsmania
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: