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


Java DefaultTreeCellRenderer类代码示例

本文整理汇总了Java中javax.swing.tree.DefaultTreeCellRenderer的典型用法代码示例。如果您正苦于以下问题:Java DefaultTreeCellRenderer类的具体用法?Java DefaultTreeCellRenderer怎么用?Java DefaultTreeCellRenderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: updateIcons

import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
public static void updateIcons(JTree tree) {
    Font defaultFont = UIManager.getFont("Tree.font");
    Font currentFont = tree.getFont();

    double newScale = (double)
            currentFont.getSize2D() / defaultFont.getSize2D();

    DefaultTreeCellRenderer renderer =
            (DefaultTreeCellRenderer) tree.getCellRenderer();
    renderer.setOpenIcon(
            scale(UIManager.getIcon("Tree.openIcon"), newScale, tree));
    renderer.setClosedIcon(
            scale(UIManager.getIcon("Tree.closedIcon"), newScale, tree));
    renderer.setLeafIcon(
            scale(UIManager.getIcon("Tree.leafIcon"), newScale, tree));

    Collection<Integer> iconSizes = Arrays.asList(
            renderer.getOpenIcon().getIconHeight(),
            renderer.getClosedIcon().getIconHeight(),
            renderer.getLeafIcon().getIconHeight());

    // Convert points to pixels
    Point2D p = new Point2D.Float(0, currentFont.getSize2D());
    FontRenderContext context =
            tree.getFontMetrics(currentFont).getFontRenderContext();
    context.getTransform().transform(p, p);
    int fontSizeInPixels = (int) Math.ceil(p.getY());

    tree.setRowHeight(
            Math.max(fontSizeInPixels, Collections.max(iconSizes) + 2));
}
 
开发者ID:phweda,项目名称:MFM,代码行数:32,代码来源:SwingUtils.java

示例2: getTreeCellRendererComponent

import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
@Override
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
		boolean leaf, int row, boolean hasFocus) {
	Component renderer = delegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
	((DefaultTreeCellRenderer) renderer).setLeafIcon(null);
	((DefaultTreeCellRenderer) renderer).setIcon(null);
	((DefaultTreeCellRenderer) renderer).setOpenIcon(null);
	((DefaultTreeCellRenderer) renderer).setClosedIcon(null);

	TreePath path = tree.getPathForRow(row);
	if (path != null) {
		if (selectionModel.isPathSelected(path, true)) {
			checkBox.setState(Boolean.TRUE);
		} else {
			checkBox.setState(selectionModel.isPartiallySelected(path) ? null : Boolean.FALSE);
		}
	}
	removeAll();
	add(checkBox, BorderLayout.WEST);
	add(renderer, BorderLayout.CENTER);
	return this;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:23,代码来源:ExtendedCheckTreeCellRenderer.java

示例3: CellRenderer

import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
 * Empty constructor with the correct visibility.
 * @param tree the enclosing checkbox tree
 */
CellRenderer(CheckboxTree tree) {
    this.tree = tree;
    this.jLabel = new DefaultTreeCellRenderer();
    this.jLabel.setOpenIcon(null);
    this.jLabel.setLeafIcon(null);
    this.jLabel.setClosedIcon(null);
    this.jLabel.setBorder(INSET_BORDER);
    this.checkbox = new JCheckBox();
    this.checkbox.setOpaque(false);
    setLayout(new BorderLayout());
    add(this.jLabel, BorderLayout.CENTER);
    add(this.checkbox, CheckboxTree.CHECKBOX_ORIENTATION);
    setBorder(new EmptyBorder(0, 2, 0, 0));
    setComponentOrientation(this.tree.getComponentOrientation());
    setOpaque(false);
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:21,代码来源:CheckboxTree.java

示例4: UpdateUIRecursionTest

import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:UpdateUIRecursionTest.java

示例5: updateUI

import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
 * updateUI is overridden to set the colors of the Tree's renderer to
 * match that of the table.
 */
@Override
public void updateUI ()
{
    super.updateUI();

    // Make the tree's cell renderer use the table's cell selection
    // colors.
    TreeCellRenderer tcr = getCellRenderer();

    if (tcr instanceof DefaultTreeCellRenderer) {
        DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);

        // For 1.1 uncomment this, 1.2 has a bug that will cause an
        // exception to be thrown if the border selection color is
        // null.
        dtcr.setBorderSelectionColor(null);
        dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
        dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
    }
}
 
开发者ID:Audiveris,项目名称:audiveris,代码行数:25,代码来源:JTreeTable.java

示例6: RecordTreeCellEditor

import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
public RecordTreeCellEditor(RecordTree tree,DefaultTreeCellRenderer renderer) {
	super(tree,renderer);		
	cellEditor = new JTextArea();
	codedCellEditor = new JTextField();
	label = new JLabel();	
	coder = new JButton(new ImageIcon(getClass().getResource(
       "/com/gint/app/bisis4/client/images/coder.gif")));
	lookup = new CharacterLookup(BisisApp.getMainFrame());
	editingContainer = new Container();
	this.ownerTree = tree;
	regDlg = new RegistryDlg(BisisApp.getMainFrame());
	codedCellEditor.addKeyListener(new CellEditorKeyListener());			
	cellEditor.addKeyListener(new CellEditorKeyListener());
	coder.addKeyListener(new CellEditorKeyListener());
	coder.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e) {						
			handleOpenCoder();				
		}			
	});
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:21,代码来源:RecordTreeCellEditor.java

示例7: updateUI

import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
 * UpdateUI is overridden to set the colors of the Tree's renderer
 * to match that of the table.
 */
@Override
public void updateUI() {
    super.updateUI();
    // Make the tree's cell renderer use the table's cell selection
    // colors.
    final TreeCellRenderer tcr = getCellRenderer();
    if (tcr instanceof DefaultTreeCellRenderer) {
        final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tcr;
        // For 1.1 uncomment this, 1.2 has a bug that will cause an
        // exception to be thrown if the border selection color is
        // null.
        // renderer.setBorderSelectionColor(null);
        renderer.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
        renderer.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
    }
}
 
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:21,代码来源:TreeTableCellRenderer.java

示例8: updateUI

import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
 * updateUI is overridden to set the colors of the Tree's renderer to
 * match that of the table.
 */
public void updateUI() {
	super.updateUI();
	// Make the tree's cell renderer use the table's cell selection
	// colors.
	TreeCellRenderer tcr = getCellRenderer();
	if (tcr instanceof DefaultTreeCellRenderer) {
		DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
		// For 1.1 uncomment this, 1.2 has a bug that will cause an
		// exception to be thrown if the border selection color is
		// null.
		// dtcr.setBorderSelectionColor(null);
		dtcr.setTextSelectionColor(UIManager
				.getColor("Table.selectionForeground"));
		dtcr.setBackgroundSelectionColor(UIManager
				.getColor("Table.selectionBackground"));
		((DefaultTreeCellRenderer)this.getCellRenderer()).setLeafIcon(null);
		((DefaultTreeCellRenderer)this.getCellRenderer()).setOpenIcon(null);
		((DefaultTreeCellRenderer)this.getCellRenderer()).setClosedIcon(null);
	}
}
 
开发者ID:cst316,项目名称:spring16project-Modula-2,代码行数:25,代码来源:JTreeTable.java

示例9: updateUI

import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
     * updateUI is overridden to set the colors of the Tree's renderer to
     * match that of the table.
     */
    public void updateUI() {
        super.updateUI();
 
        // Make the tree's cell renderer use the table's cell selection
        // colors.
        TreeCellRenderer tcr = getCellRenderer();
        if (tcr instanceof DefaultTreeCellRenderer) {
            DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
 
dtcr.setBorderSelectionColor(null);
            dtcr.setTextSelectionColor(UIManager
                    .getColor("Table.selectionForeground"));
            dtcr.setBackgroundSelectionColor(UIManager
                    .getColor("Table.selectionBackground"));
        }
    }
 
开发者ID:cst316,项目名称:spring16project-Modula-2,代码行数:21,代码来源:TaskTable.java

示例10: EventPanel

import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
public EventPanel(SWEKGroup _group) {
    group = _group;
    setLayout(new BorderLayout());
    SWEKTreeModel.addSWEKTreeModelListener(this);

    JTree eventTypeTree = new JTree(new EventPanelModel(group));
    eventTypeTree.setEditable(true);
    eventTypeTree.setShowsRootHandles(true);
    eventTypeTree.setSelectionModel(null);
    eventTypeTree.setCellRenderer(new SWEKEventTreeRenderer(eventTypeTree));
    eventTypeTree.setCellEditor(new MyTreeCellEditor(eventTypeTree, (DefaultTreeCellRenderer) eventTypeTree.getCellRenderer()));

    // workaround for Win HiDpi
    if (System.getProperty("jhv.os").equals("windows")) {
        eventTypeTree.setRowHeight(new JCheckBox("J").getPreferredSize().height);
    }

    add(eventTypeTree, BorderLayout.CENTER);

    JPanel busyPanel = new JPanel();
    busyPanel.setBackground(eventTypeTree.getBackground());
    busyPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2));
    busyPanel.add(over);
    add(busyPanel, BorderLayout.LINE_END);
}
 
开发者ID:Helioviewer-Project,项目名称:JHelioviewer-SWHV,代码行数:26,代码来源:EventPanel.java

示例11: updateUI

import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
 * updateUI is overridden to set the colors of the Tree's renderer to
 * match that of the table.
 */
@Override
public void updateUI() {
	super.updateUI();
	// Make the tree's cell renderer use the table's cell selection
	// colors.
	TreeCellRenderer tcr = getCellRenderer();
	if (tcr instanceof DefaultTreeCellRenderer) {
		DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
		// For 1.1 uncomment this, 1.2 has a bug that will cause an
		// exception to be thrown if the border selection color is
		// null.
		// dtcr.setBorderSelectionColor(null);
		dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
		dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
		((DefaultTreeCellRenderer) this.getCellRenderer()).setLeafIcon(null);
		((DefaultTreeCellRenderer) this.getCellRenderer()).setOpenIcon(null);
		((DefaultTreeCellRenderer) this.getCellRenderer()).setClosedIcon(null);
	}
}
 
开发者ID:cst316,项目名称:spring16project-Fortran,代码行数:24,代码来源:JTreeTable.java

示例12: updateUI

import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
 * updateUI is overridden to set the colors of the Tree's renderer to
 * match that of the table.
 */
@Override
public void updateUI() {
	super.updateUI();

	// Make the tree's cell renderer use the table's cell selection
	// colors.
	TreeCellRenderer tcr = getCellRenderer();
	if (tcr instanceof DefaultTreeCellRenderer) {
		DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);

		dtcr.setBorderSelectionColor(null);
		dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
		dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
	}
}
 
开发者ID:cst316,项目名称:spring16project-Fortran,代码行数:20,代码来源:TaskTable.java

示例13: doNotFillBackground

import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
public static void doNotFillBackground(@NotNull final JTree tree, @NotNull final DefaultTreeCellRenderer renderer) {
  TreeUI ui = tree.getUI();
  if (ui instanceof WideSelectionTreeUI) {
    if (((WideSelectionTreeUI)ui).isWideSelection()) {
      renderer.setOpaque(false);
      try {
        final Field fillBackground = DefaultTreeCellRenderer.class.getDeclaredField("fillBackground");
        fillBackground.setAccessible(true);
        fillBackground.set(renderer, false);
      }
      catch (Exception e) {
        // nothing
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:MacUIUtil.java

示例14: getTreeCellRendererComponent

import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
                                              boolean sel,
                                              boolean expanded,
                                              boolean leaf, int row,
                                              boolean hasFocus) {
    //DefaultTreeCellRenderer.getTreeCellRendererComponent() returns itself
    JLabel element = (DefaultTreeCellRenderer) new DefaultTreeCellRenderer().getTreeCellRendererComponent(
                    tree, value, selected, expanded, leaf, row, hasFocus);

    //content of a node, could be a Path (if just directory) or a CommitFile
    Object content = ((DefaultMutableTreeNode) value).getUserObject();

    //if path, default .toString() method is called
    element.setOpaque(true);

    //if a CommitFile
    if (content instanceof Presenter) {
        element = ((Presenter)content).present(element);
    }

    return element;
}
 
开发者ID:AMOSTeam3,项目名称:amos-ss15-proj3,代码行数:24,代码来源:Tree_Renderer.java

示例15: CTagFilterTree

import javax.swing.tree.DefaultTreeCellRenderer; //导入依赖的package包/类
/**
 * Creates a new filter tree object.
 * 
 * @param tagManager Provides the tags the user can select.
 */
public CTagFilterTree(final ITagManager tagManager) {
  super(new CFilterTreeModel(tagManager.getRootTag()));

  m_tagManager = tagManager;

  setDigIn(false);

  final DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
  renderer.setOpenIcon(ICON_CONTAINER_TAG);
  renderer.setClosedIcon(ICON_CONTAINER_TAG);
  renderer.setLeafIcon(ICON_TAG);
  setCellRenderer(renderer);

  setRootVisible(false);
  TreeHelpers.expandAll(this, true);

  tagManager.addListener(m_tagManagerListener);
}
 
开发者ID:google,项目名称:binnavi,代码行数:24,代码来源:CTagFilterTree.java


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