本文整理匯總了Java中javax.swing.JTree.setCellRenderer方法的典型用法代碼示例。如果您正苦於以下問題:Java JTree.setCellRenderer方法的具體用法?Java JTree.setCellRenderer怎麽用?Java JTree.setCellRenderer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JTree
的用法示例。
在下文中一共展示了JTree.setCellRenderer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildTree
import javax.swing.JTree; //導入方法依賴的package包/類
/**
*
*/
private void buildTree() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode("user");
tree = new JTree(root);
tree.putClientProperty("JTree.lineStyle", "Angled");
tree.setCellRenderer(new NavigationTreeCellRenderer());
tree.setShowsRootHandles(true);
DefaultTreeSelectionModel model = new DefaultTreeSelectionModel();
model.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
graphsCategory = new DefaultMutableTreeNode("graphs");
mouseAdapter = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
itemSelected(e);
}
};
tree.addMouseListener(mouseAdapter);
root.add(graphsCategory);
loadGraphs();
}
示例2: createLeftPanel
import javax.swing.JTree; //導入方法依賴的package包/類
private synchronized Component createLeftPanel() {
SampleResult rootSampleResult = new SampleResult();
rootSampleResult.setSampleLabel("Root");
rootSampleResult.setSuccessful(true);
root = new SearchableTreeNode(rootSampleResult, null);
treeModel = new DefaultTreeModel(root);
jTree = new JTree(treeModel);
jTree.setCellRenderer(new ResultsNodeRenderer());
jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
jTree.addTreeSelectionListener(this);
jTree.setRootVisible(false);
jTree.setShowsRootHandles(true);
JScrollPane treePane = new JScrollPane(jTree);
treePane.setPreferredSize(new Dimension(200, 300));
VerticalPanel leftPane = new VerticalPanel();
leftPane.add(treePane, BorderLayout.CENTER);
leftPane.add(createComboRender(), BorderLayout.NORTH);
autoScrollCB = new JCheckBox(JMeterUtils.getResString("view_results_autoscroll")); // $NON-NLS-1$
autoScrollCB.setSelected(false);
autoScrollCB.addItemListener(this);
leftPane.add(autoScrollCB, BorderLayout.SOUTH);
return leftPane;
}
示例3: InfrastructureBrowserPanel
import javax.swing.JTree; //導入方法依賴的package包/類
/**
*
*/
public InfrastructureBrowserPanel() {
setLayout(new BorderLayout(0, 0));
final JPanel panel = new JPanel();
add(panel, BorderLayout.SOUTH);
btnRefresh = new JButton("Refresh");
panel.add(btnRefresh);
final JScrollPane scrollPane = new JScrollPane();
scrollPane.setPreferredSize(new Dimension(600, 500));
add(scrollPane, BorderLayout.CENTER);
model = new InfrastructureTreeModel(new ArrayList<ClusterInfo>());
tree = new JTree(model);
tree.setCellRenderer(new InfrastructureCellRenderer(tree
.getCellRenderer()));
scrollPane.setViewportView(tree);
}
示例4: UpdateUIRecursionTest
import javax.swing.JTree; //導入方法依賴的package包/類
public UpdateUIRecursionTest() {
super("UpdateUIRecursionTest");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 400);
String[] listData = {
"First", "Second", "Third", "Fourth", "Fifth", "Sixth"
};
tree = new JTree(listData);
renderer = new DefaultTreeCellRenderer();
getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
tree.setCellRenderer(this);
setVisible(true);
}
示例5: SimulationExplorer
import javax.swing.JTree; //導入方法依賴的package包/類
SimulationExplorer(Project proj, MenuListener menu) {
super(new BorderLayout());
this.project = proj;
SimulationToolbarModel toolbarModel = new SimulationToolbarModel(proj, menu);
Toolbar toolbar = new Toolbar(toolbarModel);
add(toolbar, BorderLayout.NORTH);
model = new SimulationTreeModel(proj.getSimulator().getCircuitState());
model.setCurrentView(project.getCircuitState());
tree = new JTree(model);
tree.setCellRenderer(new SimulationTreeRenderer());
tree.addMouseListener(this);
tree.setToggleClickCount(3);
add(new JScrollPane(tree), BorderLayout.CENTER);
proj.addProjectListener(this);
}
示例6: ExtendedCheckTreeMouseSelectionManager
import javax.swing.JTree; //導入方法依賴的package包/類
public ExtendedCheckTreeMouseSelectionManager(JTree tree, boolean selectAll) {
this.tree = tree;
selectionModel = new ExtendedCheckTreeSelectionModel(tree.getModel());
if (selectAll) {
selectionModel.addSelectionPath(tree.getPathForRow(0));
}
tree.setCellRenderer(new ExtendedCheckTreeCellRenderer(new DefaultTreeCellRenderer(), selectionModel));
tree.addMouseListener(this);
selectionModel.addTreeSelectionListener(this);
}
示例7: SwingSpyPanel
import javax.swing.JTree; //導入方法依賴的package包/類
/**
* Initialization.
*/
public SwingSpyPanel() {
setPreferredSize(new Dimension(INITIAL_WIDTH, INITIAL_HEIGHT));
setLayout(new BorderLayout());
root = new DefaultMutableTreeNode();
componentTree = new JTree(root);
componentTree.setRootVisible(false);
componentTree.setCellRenderer(new SwingComponentRenderer());
componentTree.addTreeSelectionListener(new CustomSelectionListener());
// add(new JScrollPane(componentTree), BorderLayout.CENTER);
detailsData = new JEditorPane();
detailsData.setBackground(new Color(250, 250, 250));
detailsData.setForeground(new Color(33, 33, 33));
detailsData.setBorder(BorderFactory.createLineBorder(new Color(100, 100, 244), 1));
detailsData.setPreferredSize(new Dimension(150, INITIAL_HEIGHT));
detailsData.setEditable(false);
detailsData.setContentType("text/html");
SwingUtil.enforceJEditorPaneFont(detailsData, font);
detailsScrollPane = new JScrollPane(detailsData);
// add(detailsScrollPane, BorderLayout.EAST);
JSplitPane hPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(componentTree), detailsScrollPane);
hPane.setContinuousLayout(true);
hPane.setOneTouchExpandable(true);
hPane.setDividerLocation(INITIAL_WIDTH - 200);
add(hPane, BorderLayout.CENTER);
componentData = new JEditorPane();
componentData.setBackground(new Color(250, 250, 250));
componentData.setForeground(new Color(33, 33, 33));
componentData.setBorder(BorderFactory.createLineBorder(new Color(100, 100, 244), 1));
componentData.setPreferredSize(new Dimension(INITIAL_WIDTH, 36));
componentData.setEditable(false);
componentData.setContentType("text/html");
SwingUtil.enforceJEditorPaneFont(componentData, font);
add(componentData, BorderLayout.SOUTH);
}
示例8: buildMainPanel
import javax.swing.JTree; //導入方法依賴的package包/類
protected Component buildMainPanel() {
JPanel keyPanel = buildKeyTablePanel();
/*
* Tree of all components from target component down
*/
JPanel treePanel = new JPanel(new BorderLayout());
MyTreeNode top = new MyTreeNode(target);
createNodes(top);
tree = new JTree(top);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addTreeSelectionListener(this);
tree.setSelectionRow(0);
tree.setCellRenderer(new MyTreeCellRenderer());
JScrollPane treeScroll = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
treePanel.add(treeScroll, BorderLayout.CENTER);
treePanel.setMinimumSize(new Dimension(400, 100));
treePanel.setPreferredSize(new Dimension(800, 300));
/*
* First split between Tree display and Keys
*/
JSplitPane split1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, treePanel, keyPanel);
split1.setResizeWeight(0.5);
return split1;
}
示例9: setupGui
import javax.swing.JTree; //導入方法依賴的package包/類
private void setupGui(ClientService clientService, PluginService pluginService)
{
model = new SecurityTreeModel(clientService, pluginService);
tree = new JTree(model);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setCellRenderer(new MyTreeCellRenderer());
tree.addTreeSelectionListener(this);
tabManager = new TabManager(clientService, allowEditing);
JScrollPane scroller = new JScrollPane(tree);
scroller.setMinimumSize(new Dimension(200, Integer.MAX_VALUE));
JSplitPane split = AppletGuiUtils.createSplitPane();
split.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
split.setContinuousLayout(true);
split.add(scroller, JSplitPane.LEFT);
split.add(tabManager, JSplitPane.RIGHT);
JButton closeButton = new JButton(closeAction);
final int[] rows = {TableLayout.FILL, closeButton.getPreferredSize().height,};
final int[] cols = {TableLayout.FILL, closeButton.getPreferredSize().width,};
content = new JPanel(new TableLayout(rows, cols));
content.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
content.add(split, new Rectangle(0, 0, 2, 1));
content.add(closeButton, new Rectangle(1, 1, 1, 1));
updateEditor();
}
示例10: init
import javax.swing.JTree; //導入方法依賴的package包/類
private void init() {
treeModel.setRoot(createRoot());
tree = new JTree(treeModel) {
@Override
public TreeCellRenderer getCellRenderer() {
TreeCellRenderer renderer = super.getCellRenderer();
if (renderer == null)
return null;
((DefaultTreeCellRenderer) renderer).setLeafIcon(new ImageIcon(
getClass().getResource("/images/function.png")));
return renderer;
}
};
tree.setCellRenderer(new Renderer());
tree.setEditable(true);
tree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if ((e.getButton() == MouseEvent.BUTTON1)
&& (e.getClickCount() == 2)) {
openDiagram();
}
}
});
tree.setRootVisible(true);
JScrollPane pane = new JScrollPane();
pane.setViewportView(tree);
this.add(pane, BorderLayout.CENTER);
}
示例11: buildTree
import javax.swing.JTree; //導入方法依賴的package包/類
/**
* Builds the JTree which represents the navigation menu and then returns it
*
* @return The navigation tree.
*/
private JTree buildTree() {
String name = Messages.message("colopedia");
DefaultMutableTreeNode root
= new DefaultMutableTreeNode(new ColopediaTreeItem(null, null, name, null));
FreeColClient fcc = getFreeColClient();
new TerrainDetailPanel(fcc, this).addSubTrees(root);
new ResourcesDetailPanel(fcc, this).addSubTrees(root);
new GoodsDetailPanel(fcc, this).addSubTrees(root);
new UnitDetailPanel(fcc, this).addSubTrees(root);
new BuildingDetailPanel(fcc, this).addSubTrees(root);
new FatherDetailPanel(fcc, this).addSubTrees(root);
new NationDetailPanel(fcc, this).addSubTrees(root);
new NationTypeDetailPanel(fcc, this).addSubTrees(root);
new ConceptDetailPanel(fcc, this).addSubTrees(root);
DefaultTreeModel treeModel = new DefaultTreeModel(root);
tree = new JTree(treeModel) {
@Override
public Dimension getPreferredSize() {
return new Dimension(
(int)(200 * getImageLibrary().getScaleFactor()),
super.getPreferredSize().height);
}
};
tree.setRootVisible(false);
tree.setCellRenderer(new ColopediaTreeCellRenderer());
tree.setOpaque(false);
tree.addTreeSelectionListener(this);
listPanel.add(tree);
Enumeration allNodes = root.depthFirstEnumeration();
while (allNodes.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) allNodes.nextElement();
ColopediaTreeItem item = (ColopediaTreeItem) node.getUserObject();
nodeMap.put(item.getId(), node);
}
return tree;
}
示例12: addWindowTab
import javax.swing.JTree; //導入方法依賴的package包/類
private void addWindowTab() {
if (compNode instanceof WindowNode
&& ((WindowNode) compNode).getWindows().length > 0) {
winTree = new JTree(((WindowNode) compNode).getWindowModel());
winTree.setCellRenderer(renderer);
winTree.setEditable(false);
winTree.addTreeSelectionListener(selManager);
winSplit = createUnderPane(winTree);
tbd.add(WINDOWS_TAB, winSplit);
}
}
示例13: addComponentTab
import javax.swing.JTree; //導入方法依賴的package包/類
private void addComponentTab() {
if (compNode instanceof ContainerNode
&& ((ContainerNode) compNode).getComponents().length > 0) {
componentTree = new JTree(((ContainerNode) compNode).getComponentModel());
componentTree.setCellRenderer(renderer);
componentTree.setEditable(false);
componentTree.addTreeSelectionListener(selManager);
componentSplit = createUnderPane(componentTree);
tbd.add(COMPONENTS_TAB, componentSplit);
}
}
示例14: initializeTree
import javax.swing.JTree; //導入方法依賴的package包/類
private void initializeTree() {
tree = new JTree();
tree.setCellRenderer(new CustomTreeRenderer());
tree.setVisibleRowCount(8);
tree.setBackground(background);
tree.addTreeSelectionListener(this);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setShowsRootHandles(true);
}
示例15: TreeIconDemo
import javax.swing.JTree; //導入方法依賴的package包/類
public TreeIconDemo() {
super(new GridLayout(1, 0));
// Create the nodes.
DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series");
createNodes(top);
// Create a tree that allows one selection at a time.
tree = new JTree(top);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
// Set the icon for leaf nodes.
ImageIcon leafIcon = createImageIcon("images/middle.gif");
if (leafIcon != null) {
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setLeafIcon(leafIcon);
tree.setCellRenderer(renderer);
} else {
System.err.println("Leaf icon missing; using default.");
}
// Listen for when the selection changes.
tree.addTreeSelectionListener(this);
// Create the scroll pane and add the tree to it.
JScrollPane treeView = new JScrollPane(tree);
// Create the HTML viewing pane.
htmlPane = new JEditorPane();
htmlPane.setEditable(false);
initHelp();
JScrollPane htmlView = new JScrollPane(htmlPane);
// Add the scroll panes to a split pane.
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.setTopComponent(treeView);
splitPane.setBottomComponent(htmlView);
Dimension minimumSize = new Dimension(100, 50);
htmlView.setMinimumSize(minimumSize);
treeView.setMinimumSize(minimumSize);
splitPane.setDividerLocation(100); // XXX: ignored in some releases
// of Swing. bug 4101306
// workaround for bug 4101306:
// treeView.setPreferredSize(new Dimension(100, 100));
splitPane.setPreferredSize(new Dimension(500, 300));
// Add the split pane to this panel.
add(splitPane);
}