private void createTreeLayout(JTree theTree) { DefaultTreeCellRenderer moduleNodeRenderer = new SoftwareTreeCellRenderer(dataControl); moduleNodeRenderer.setBackground(UIManager.getColor("Panel.background")); moduleNodeRenderer.setBackgroundNonSelectionColor(UIManager.getColor("Panel.background")); moduleNodeRenderer.setBackgroundSelectionColor(UIManager.getColor("Table.sortIconColor")); moduleNodeRenderer.setTextNonSelectionColor(UIManager.getColor("Panel.background")); moduleNodeRenderer.setTextSelectionColor(UIManager.getColor("Table.sortIconColor")); theTree.setCellRenderer(moduleNodeRenderer); theTree.setBackground(PANELBACKGROUND); }
private void createPanel() { AnalysedModuleDTO rootModule = new AnalysedModuleDTO("Application", "Application", "root", "public"); DefaultMutableTreeNode root = new DefaultMutableTreeNode(rootModule); List<AnalysedModuleDTO> rootModules = dataControl.getRootModules(); for (AnalysedModuleDTO module : rootModules) { DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(module); root.add(rootNode); } analyzedCodeTree = new JTree(root); analyzedCodeTree.setBackground(UIManager.getColor("Panel.background")); analyzedCodeTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); analyzedCodeTree.addTreeSelectionListener(this); jScrollPaneTree = new JScrollPane(analyzedCodeTree); jScrollPaneTree.setBorder(null); jScrollPaneTree.setBackground(getBackground()); jScrollPaneTree.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); GroupLayout groupLayout = new GroupLayout(this); groupLayout.setHorizontalGroup( groupLayout .createParallelGroup(Alignment.LEADING) .addGroup( groupLayout .createSequentialGroup() .addContainerGap() .addComponent(jScrollPaneTree, GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE) .addContainerGap())); groupLayout.setVerticalGroup( groupLayout .createParallelGroup(Alignment.LEADING) .addGroup( groupLayout .createSequentialGroup() .addGap(5) .addComponent(jScrollPaneTree, GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE) .addContainerGap())); DefaultTreeCellRenderer renderer = new SoftwareTreeCellRenderer(); renderer.setBackground(UIManager.getColor("Panel.background")); renderer.setBackgroundNonSelectionColor(UIManager.getColor("Panel.background")); renderer.setBackgroundSelectionColor(UIManager.getColor("Panel.background")); renderer.setTextNonSelectionColor(Color.black); renderer.setTextSelectionColor(Color.black); analyzedCodeTree.setCellRenderer(renderer); setLayout(groupLayout); }
/** * base interaction with list: renderer uses list's unselected custom colors. * * <p>currently, this test fails because the assumptions are wrong! Core renderer behaves slightly * unexpected. */ public void testTreeRendererExtTreeColors() { Color background = Color.MAGENTA; Color foreground = Color.YELLOW; tree.setBackground(background); tree.setForeground(foreground); coreTreeRenderer.setBackgroundNonSelectionColor(background); coreTreeRenderer.setTextNonSelectionColor(foreground); // prepare standard Component coreComponent = coreTreeRenderer.getTreeCellRendererComponent(tree, null, false, false, false, 0, false); // sanity: known standard behaviour // background is manually painted assertEquals(background, coreComponent.getBackground()); assertEquals(tree.getForeground(), coreComponent.getForeground()); // prepare extended Component xComponent = xTreeRenderer.getTreeCellRendererComponent(tree, null, false, false, false, 0, false); // assert behaviour same as standard assertEquals(background, xComponent.getBackground()); assertEquals(foreground, xComponent.getForeground()); }