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

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

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

JTree.getHeight介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

//create a tree data structure
 DefaultMutableTreeNode tree = new DefaultMutableTreeNode("root");
 //optional: you can make the tree really big
 //now show the tree
 JFrame frame = new JFrame("TreeDemo");
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 //Create a Jtree component to display your data structure 
 JTree treeDisplay = new JTree(tree);
 //expand the tree all out
 for(int i = 0; i < treeDisplay.getRowCount(); i++) {
   treeDisplay.expandRow(i);
 }
 //put your tree display component in a scroll pane
 frame.add(new JScrollPane(treeDisplay));
 //Display the window.
 frame.pack();
 frame.setVisible(true);
 //save tree in the window to a file
 BufferedImage img = new BufferedImage(treeDisplay.getWidth(), treeDisplay.getHeight(), BufferedImage.TYPE_INT_RGB);
 Graphics2D graphics = img.createGraphics();
 //put graphics on the buffered image
 treeDisplay.paintAll(graphics);    
 graphics.dispose();
 try {
   ImageIO.write(img, "png", new File("tree.png"));
 }
 catch (IOException e) {
   e.printStackTrace();
 }

代码示例来源:origin: net.java.dev.laf-widget/laf-widget

protected void doAutoscroll(Point aPoint) {
    if (this.viewport == null)
      return;

    Point treePosition = this.viewport.getViewPosition();
    int vH = this.viewport.getExtentSize().height;
    int vW = this.viewport.getExtentSize().width;
    Point nextPoint = null;
    if ((aPoint.y - treePosition.y) < AutoScrollingTreeDropTarget.AUTOSCROLL_MARGIN) {
      nextPoint = new Point(treePosition.x, Math.max(treePosition.y
          - this.scrollUnits, 0));
    } else if (treePosition.y + vH - aPoint.y < AutoScrollingTreeDropTarget.AUTOSCROLL_MARGIN) {
      nextPoint = new Point(treePosition.x, Math.min(aPoint.y
          + AutoScrollingTreeDropTarget.AUTOSCROLL_MARGIN, this.tree
          .getHeight()
          - vH));
    } else if (aPoint.x - treePosition.x < AutoScrollingTreeDropTarget.AUTOSCROLL_MARGIN) {
      nextPoint = new Point(Math.max(treePosition.x
          - AutoScrollingTreeDropTarget.AUTOSCROLL_MARGIN, 0),
          treePosition.y);
    } else if (treePosition.x + vW - aPoint.x < AutoScrollingTreeDropTarget.AUTOSCROLL_MARGIN) {
      nextPoint = new Point(Math.min(treePosition.x
          + AutoScrollingTreeDropTarget.AUTOSCROLL_MARGIN, this.tree
          .getWidth()
          - vW), treePosition.y);
    }
    if (nextPoint != null)
      this.viewport.setViewPosition(nextPoint);
  }
}

代码示例来源:origin: UNIVALI-LITE/Portugol-Studio

@Override
  public void paint(Graphics g, JComponent c) {
    JTree tree = (JTree) c;
    
    if(tree.isOpaque()){
      g.setColor(tree.getBackground());
      g.fillRect(0, 0, tree.getWidth(), tree.getHeight());
    }
    if (tree.getSelectionCount() > 0) {
      g.setColor(ColorController.COR_DESTAQUE);
      //@see http://ateraimemo.com/Swing/TreeRowSelection.html
      for (int i : tree.getSelectionRows()) {
        Rectangle r = tree.getRowBounds(i);
        g.fillRect(0, r.y, tree.getWidth(), r.height);
      }
    }
    super.paint(g, c);
    
    if (tree.getLeadSelectionPath() != null) {
      Rectangle r = tree.getRowBounds(getRowForPath(tree, tree.getLeadSelectionPath()));
      g.setColor(tree.hasFocus() ? ColorController.FUNDO_MEDIO.brighter(): ColorController.FUNDO_MEDIO);
//            g.drawRect(0, r.y, tree.getWidth() - 1, r.height - 1);
    }
  }

代码示例来源:origin: de.sciss/jtreetable

Graphics cg = g.create(x, 0, tree.getWidth(), tree.getHeight());
try {
  cg.clipRect(clipX, 0, clipW, tree.getHeight());
  tree.paint(cg);
} finally {

相关文章

JTree类方法