當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。