javax.swing.JTree.getFont()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(109)

本文整理了Java中javax.swing.JTree.getFont()方法的一些代码示例,展示了JTree.getFont()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTree.getFont()方法的具体详情如下:
包路径:javax.swing.JTree
类名称:JTree
方法名:getFont

JTree.getFont介绍

暂无

代码示例

代码示例来源:origin: jshiell/checkstyle-idea

setFont(tree.getFont());

代码示例来源:origin: com.github.insubstantial/substance

/**
 * Gets the font of this component.
 * 
 * @return this component's font; if a font has not been set for this
 *         component, the font of its parent is returned
 */
@Override
public Font getFont() {
  Font font = super.getFont();
  if ((font == null) && (this.tree != null)) {
    // Strive to return a non-null value, otherwise the html support
    // will typically pick up the wrong font in certain situations.
    font = this.tree.getFont();
  }
  return font;
}

代码示例来源:origin: org.java.net.substance/substance

/**
 * Gets the font of this component.
 * 
 * @return this component's font; if a font has not been set for this
 *         component, the font of its parent is returned
 */
@Override
public Font getFont() {
  Font font = super.getFont();
  if ((font == null) && (this.tree != null)) {
    // Strive to return a non-null value, otherwise the html support
    // will typically pick up the wrong font in certain situations.
    font = this.tree.getFont();
  }
  return font;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui

/**
 * Gets the font of this component.
 *
 * @return this component's font; if a font has not been set
 *         for this component, the font of its parent is returned
 */
public Font getFont() {
  Font font = super.getFont();
  if ((font == null) && (tree != null)) {
    // Strive to return a non-null value, otherwise the html support
    // will typically pick up the wrong font in certain situations.
    font = tree.getFont();
  }
  return font;
}

代码示例来源:origin: com.jidesoft/jide-oss

/**
 * Gets the font of this component.
 *
 * @return this component's font; if a font has not been set for this component, the font of its parent is returned
 */
@Override
public Font getFont() {
  Font font = super.getFont();
  if (font == null && tree != null) {
    // Strive to return a non-null value, otherwise the html support
    // will typically pick up the wrong font in certain situations.
    font = tree.getFont();
  }
  return font;
}

代码示例来源:origin: net.java.dev.swing-layout/swing-layout

private int getTreeBaseline(JTree tree, int height) {
  int rowHeight = tree.getRowHeight();
  if (TREE_LABEL == null) {
    TREE_LABEL = new JLabel("X");
    TREE_LABEL.setIcon(UIManager.getIcon("Tree.closedIcon"));
  }
  JLabel label = TREE_LABEL;
  label.setFont(tree.getFont());
  if (rowHeight <= 0) {
    rowHeight = label.getPreferredSize().height;
  }
  return getLabelBaseline(label, rowHeight) + tree.getInsets().top;
}

代码示例来源:origin: net.java.dev.swing-layout/swing-layout

private static int getTreeBaseline(JTree tree, int height) {
  int rowHeight = tree.getRowHeight();
  if (TREE_LABEL == null) {
    TREE_LABEL = new JLabel("X");
    TREE_LABEL.setIcon(UIManager.getIcon("Tree.closedIcon"));
  }
  JLabel label = TREE_LABEL;
  label.setFont(tree.getFont());
  if (rowHeight <= 0) {
    rowHeight = label.getPreferredSize().height;
  }
  return getLabelBaseline(label, rowHeight) + tree.getInsets().top;
}

代码示例来源:origin: cytoscape.coreplugins/cpath2

label.setFont(tree.getFont());
label.setText(stringValue);
if (leaf) {

代码示例来源:origin: org.cytoscape/cpath2-impl

label.setFont(tree.getFont());
label.setText(stringValue);
if (leaf) {

代码示例来源:origin: org.fudaa.framework.ebli/ebli-2d

public Component getTreeCellRendererComponent(final JTree _tree, final Object _value, final boolean _selected,
   final boolean _expanded, final boolean _leaf, final int _row, final boolean _hasFocus) {
  this.setFont(_tree.getFont());
  setIcon((Icon) _value);
  setText(_value.toString());
  if (_selected) {
   setBackground(selectedBack_);
   setForeground(selectedFor_);
  } else {
   setBackground(UIManager.getColor("Tree.background"));
   setForeground(UIManager.getColor("Tree.foreground"));
  }
  return this;
 }
}

代码示例来源:origin: org.biomoby/taverna-biomoby

public void paint(Graphics g) {
    boolean selected = tree.isRowSelected(row);
    Component renderer = tree
        .getCellRenderer()
        .getTreeCellRendererComponent(
            tree,
            path.getLastPathComponent(),
            tree.isRowSelected(row),
            tree.isExpanded(row),
            tree.getModel().isLeaf(path.getLastPathComponent()),
            row, selected);
    c.setFont(tree.getFont());
    Rectangle paintBounds = SwingUtilities.convertRectangle(tree,
        bounds, this);
    SwingUtilities.paintComponent(g, renderer, this, paintBounds);
    if (selected)
      return;
    g.setColor(Color.blue);
    ((Graphics2D) g).draw(paintBounds);
  }
};

代码示例来源:origin: io.ultreia.java4all.jaxx/jaxx-widgets-extra

public Component getRendererComponent() {
  TreeModel treeModel = tree.getModel();
  TreePath treePath = tree.getPathForRow(rowIndex);
  TreeCellRenderer renderer = tree.getCellRenderer();
  boolean isSelected = tree.isPathSelected(treePath);
  boolean isExpanded = tree.isExpanded(treePath);
  boolean hasFocus = tree.hasFocus() && rowIndex == tree.getLeadSelectionRow();
  Object item = treePath.getLastPathComponent();
  boolean isLeaf = treeModel.isLeaf(item);
  Component component = renderer.getTreeCellRendererComponent(tree, item, isSelected, isExpanded, isLeaf, rowIndex, hasFocus);
  component.setFont(tree.getFont());
  // FIX Nimbus white foreground on white background
  if (isSelected) {
    component.setForeground(UIManager.getColor("Tree.textForeground"));
  }
  return component;
}

代码示例来源:origin: org.nuiton/nuiton-widgets

public Component getRendererComponent() {
  TreeModel treeModel = tree.getModel();
  TreePath treePath = tree.getPathForRow(rowIndex);
  TreeCellRenderer renderer = tree.getCellRenderer();
  boolean isSelected = tree.isPathSelected(treePath);
  boolean isExpanded = tree.isExpanded(treePath);
  boolean hasFocus = tree.hasFocus() && rowIndex == tree.getLeadSelectionRow();
  Object item = treePath.getLastPathComponent();
  boolean isLeaf = treeModel.isLeaf(item);
  Component component = renderer.getTreeCellRendererComponent(tree, item, isSelected, isExpanded, isLeaf, rowIndex, hasFocus);
  component.setFont(tree.getFont());
  
  // FIX Nimbus white foreground on white background
  if (isSelected) {
    component.setForeground(UIManager.getColor("Tree.textForeground"));
  }
  return component;
}

代码示例来源:origin: info.aduna.commons/aduna-commons-swing

public void paint(Graphics g) {
    boolean selected = tree.isRowSelected(row);
    TreePath path = TreeOverlay.this.path;
    if (path != null) {
      JComponent renderer = (JComponent) tree.getCellRenderer().getTreeCellRendererComponent(tree,
          path.getLastPathComponent(), tree.isRowSelected(row), tree.isExpanded(row),
          tree.getModel().isLeaf(path.getLastPathComponent()), row, selected);
      setFont(tree.getFont());
      Rectangle paintBounds = SwingUtilities.convertRectangle(tree, bounds, this);
      SwingUtilities.paintComponent(g, renderer, this, paintBounds);
      int spacing = 0;
      if (renderer instanceof JLabel) {
        JLabel label = (JLabel) renderer;
        if (label.getIcon() != null) {
          spacing = label.getHorizontalTextPosition() + label.getIconTextGap();
        }
      }
      g.setColor(Color.BLACK);
      g.drawRect(paintBounds.x + spacing, paintBounds.y, paintBounds.width - spacing, paintBounds.height);
    }
  }
}

代码示例来源:origin: org.icepdf.os/icepdf-viewer

public Component getTreeCellRendererComponent(JTree tree, Object value,
                       boolean isSelected, boolean expanded,
                       boolean leaf, int row, boolean hasFocus) {
  String stringValue = tree.convertValueToText(value, isSelected,
      expanded, leaf, row, hasFocus);
  setEnabled(tree.isEnabled());
  if (value instanceof LayersTreeNode) {
    checkBox.setSelected(((LayersTreeNode) value).isSelected());
  }
  treeLabel.setFont(tree.getFont());
  treeLabel.setText(stringValue);
  treeLabel.setSelected(isSelected);
  treeLabel.setFocus(hasFocus);
  return this;
}

代码示例来源:origin: org.n52.wps/52n-wps-install-wizard

public Component getTreeCellRendererComponent(JTree tree, Object value,
       boolean isSelected, boolean expanded,
       boolean leaf, int row, boolean hasFocus) {
 String  stringValue = tree.convertValueToText(value, isSelected,
     expanded, leaf, row, hasFocus);
 setEnabled(tree.isEnabled());
 check.setSelected(((CheckNode)value).isSelected());
 label.setFont(tree.getFont());
 label.setText(stringValue);
 label.setSelected(isSelected);
 label.setFocus(hasFocus);
 if (leaf) {
  label.setIcon(UIManager.getIcon("Tree.leafIcon"));
 } else if (expanded) {
  label.setIcon(UIManager.getIcon("Tree.openIcon"));
 } else {
  label.setIcon(UIManager.getIcon("Tree.closedIcon"));
 }        
 return this;
}

代码示例来源:origin: igniterealtime/Spark

public Component getTreeCellRendererComponent(JTree tree, Object value,
                       boolean isSelected, boolean expanded,
                       boolean leaf, int row, boolean hasFocus) {
  String stringValue = tree.convertValueToText(value, isSelected,
    expanded, leaf, row, hasFocus);
  setEnabled(tree.isEnabled());
  check.setSelected(((CheckNode)value).isSelected());
  label.setFont(tree.getFont());
  label.setText(stringValue);
  label.setSelected(isSelected);
  label.setFocus(hasFocus);
  if (leaf) {
    Icon icon = ((CheckNode)value).getIcon();
    label.setIcon(icon);
  }
  else if (expanded) {
    label.setIcon(UIManager.getIcon("Tree.openIcon"));
  }
  else {
    label.setIcon(UIManager.getIcon("Tree.closedIcon"));
  }
  return this;
}

代码示例来源:origin: Jamling/SmartIM

/**
 * 返回的是一个<code>JPanel</code>对象,该对象中包含一个<code>JCheckBox</code>对象 和一个
 * <code>JLabel</code>对象。并且根据每个结点是否被选中来决定<code>JCheckBox</code> 是否被选中。
 */
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
    boolean selected, boolean expanded, boolean leaf, int row,
    boolean hasFocus) {
  String stringValue = tree.convertValueToText(value, selected, expanded,
      leaf, row, hasFocus);
  setEnabled(tree.isEnabled());
  if (value instanceof CheckBoxTreeNode) {
    check.setSelected(((CheckBoxTreeNode) value).isSelected());
  }
  label.setFont(tree.getFont());
  label.setText(stringValue);
  label.setSelected(selected);
  label.setFocus(hasFocus);
  if (leaf)
    label.setIcon(UIManager.getIcon("Tree.leafIcon"));
  else if (expanded)
    label.setIcon(UIManager.getIcon("Tree.openIcon"));
  else
    label.setIcon(UIManager.getIcon("Tree.closedIcon"));
    
  return this;
}

代码示例来源:origin: org.fudaa.framework.ebli/ebli-2d

public Component getTreeCellRendererComponent(final JTree _tree, final Object _value, final boolean _selected,
   final boolean _expanded, final boolean _leaf, final int _row, final boolean _hasFocus) {
  this.setFont(_tree.getFont());
  setIcon(((LayerNode) _value).getIcon());
  setText(_value.toString());
  final boolean selectable = isSelectable(_value, _leaf);
  if (_selected && selectable) {
   setBackground(selectedBackground_);
   setForeground(selectedForground_);
  } else {
   setBackground(_tree.getBackground());
   setForeground(_tree.getForeground());
  }
  if (selectable) {
   setToolTipText(getText());
  } else {
   setToolTipText(getText() + ": " + CtuluLib.getS("Non slectionnable"));
  }
  setBorder((selectable && _hasFocus) ? focusBorderColor_ : CtuluCellRenderer.BORDER_NO_FOCUS);
  setEnabled(_tree.isEnabled());
  return this;
 }
}

代码示例来源:origin: org.fudaa.framework.ebli/ebli-2d

public Component getTreeCellRendererComponent(final JTree _tree, final Object _value, final boolean _selected,
   final boolean _expanded, final boolean _leaf, final int _row, final boolean _hasFocus) {
  this.setFont(_tree.getFont());
  setIcon(((LayerNode) _value).getIcon());
  setText(_value.toString());
  final boolean selectable = isSelectable(_value, _leaf);
  if (_selected && selectable) {
   setBackground(selectedBackground_);
   setForeground(selectedForground_);
  } else {
   setBackground(_tree.getBackground());
   setForeground(_tree.getForeground());
  }
  if (selectable) {
   setToolTipText(getText());
  } else {
   setToolTipText(getText() + ": " + CtuluLib.getS("Non slectionnable"));
  }
  setBorder((selectable && _hasFocus) ? focusBorderColor_ : CtuluCellRenderer.BORDER_NO_FOCUS);
  setEnabled(_tree.isEnabled());
  return this;
 }
}

相关文章

JTree类方法