当前位置: 首页>>代码示例>>Java>>正文


Java JTree.setOpaque方法代码示例

本文整理汇总了Java中javax.swing.JTree.setOpaque方法的典型用法代码示例。如果您正苦于以下问题:Java JTree.setOpaque方法的具体用法?Java JTree.setOpaque怎么用?Java JTree.setOpaque使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTree的用法示例。


在下文中一共展示了JTree.setOpaque方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:45,代码来源:ColopediaPanel.java

示例2: OptionGroupUI

import javax.swing.JTree; //导入方法依赖的package包/类
/**
 * The constructor that will add the items to this panel.
 *
 * @param gui The enclosing {@code GUI}.
 * @param group The {@code OptionGroup} encapsulate.
 * @param editable Is the group editable.
 */
public OptionGroupUI(GUI gui, OptionGroup group, boolean editable) {
    super("ReportPanelUI");

    this.gui = gui;
    this.group = group;
    this.editable = editable;

    setLayout(new MigLayout("fill", "[200:]unrelated[550:, grow, fill]",
                            "[top]"));

    DefaultMutableTreeNode root = new DefaultMutableTreeNode(group);
    buildTree(group, root);

    DefaultTreeModel treeModel = new DefaultTreeModel(root);
    tree = new JTree(treeModel) {
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(200, super.getPreferredSize().height);
            }
            @Override
            public String convertValueToText(Object value,
                boolean selected, boolean expanded,
                boolean leaf, int row, boolean hasFocus) {
                DefaultMutableTreeNode node
                    = (DefaultMutableTreeNode)value;
                Option option = (Option)node.getUserObject();
                return Messages.getName(option.getId());
            }
        };

    tree.setOpaque(false);
    tree.addTreeSelectionListener(this);
    DefaultTreeCellRenderer renderer
        = (DefaultTreeCellRenderer)tree.getCellRenderer();
    renderer.setBackgroundNonSelectionColor(new Color(0, 0, 0, 1));

    add(tree);
    detailPanel = new MigPanel();
    detailPanel.setLayout(new MigLayout("wrap 2", "[fill]related[fill]"));
    detailPanel.setOpaque(false);
    add(detailPanel, "grow");
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:50,代码来源:OptionGroupUI.java


注:本文中的javax.swing.JTree.setOpaque方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。