本文整理了Java中javax.swing.JTree.getWidth()
方法的一些代码示例,展示了JTree.getWidth()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTree.getWidth()
方法的具体详情如下:
包路径:javax.swing.JTree
类名称:JTree
方法名:getWidth
暂无
代码示例来源:origin: jcbvm/i18n-editor
private Rectangle getPathBounds(TreePath path, Insets insets, Rectangle bounds) {
bounds = treeState.getBounds(path, bounds);
if (bounds != null) {
bounds.x = 0;
bounds.y += insets.top;
bounds.width = tree.getWidth();
}
return bounds;
}
}
代码示例来源: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: de.sciss/jtreetable
protected void paintTreeComponent(Graphics g, Component c) {
int x = 0;
int y = 0;
int w = getWidth();
int h = getHeight();
if (getX() + w > tree.getWidth())
w = tree.getWidth() - getX();
// only shift y-axis, tree's bounds are already shifted for x-axis
y += top;
h -= top + bottom;
paintComponent(g, c, null, x, y, w, h, true);
}
代码示例来源: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: org.java.net.substance/substance
public void run() {
if (SubstanceTreeUI.this.tree == null) {
// may happen if the LAF was switched in the meantime
return;
}
Rectangle boundsBuffer = new Rectangle();
Rectangle bounds = treeState.getBounds(treePath,
boundsBuffer);
if (bounds != null) {
// still visible
// fix for defect 180 - refresh the entire row
bounds.x = 0;
bounds.width = tree.getWidth();
// fix for defect 188 - rollover effects for trees
// with insets
Insets insets = tree.getInsets();
bounds.x += insets.left;
bounds.y += insets.top;
tree.repaint(bounds);
}
}
});
代码示例来源:origin: com.github.insubstantial/substance
@Override
public void run() {
if (SubstanceTreeUI.this.tree == null) {
// may happen if the LAF was switched in the meantime
return;
}
Rectangle boundsBuffer = new Rectangle();
Rectangle bounds = treeState.getBounds(treePath,
boundsBuffer);
if (bounds != null) {
// still visible
// fix for defect 180 - refresh the entire row
bounds.x = 0;
bounds.width = tree.getWidth();
// fix for defect 188 - rollover effects for trees
// with insets
Insets insets = tree.getInsets();
bounds.x += insets.left;
bounds.y += insets.top;
tree.repaint(bounds);
}
}
});
代码示例来源:origin: org.bidib.jbidib.swinglabs.swingx/swingx-core
@Override
protected void rollover(Point oldLocation, Point newLocation) {
// JW: conditional repaint not working?
// component.repaint();
if (oldLocation != null) {
Rectangle r = component.getRowBounds(oldLocation.y);
if (r != null) {
r.x = 0;
r.width = component.getWidth();
component.repaint(r);
}
}
if (newLocation != null) {
Rectangle r = component.getRowBounds(newLocation.y);
if (r != null) {
r.x = 0;
r.width = component.getWidth();
component.repaint(r);
}
}
setRolloverCursor(newLocation);
}
代码示例来源:origin: org.swinglabs.swingx/swingx-core
@Override
protected void rollover(Point oldLocation, Point newLocation) {
// JW: conditional repaint not working?
// component.repaint();
if (oldLocation != null) {
Rectangle r = component.getRowBounds(oldLocation.y);
if (r != null) {
r.x = 0;
r.width = component.getWidth();
component.repaint(r);
}
}
if (newLocation != null) {
Rectangle r = component.getRowBounds(newLocation.y);
if (r != null) {
r.x = 0;
r.width = component.getWidth();
component.repaint(r);
}
}
setRolloverCursor(newLocation);
}
代码示例来源:origin: com.haulmont.thirdparty/swingx-core
@Override
protected void rollover(Point oldLocation, Point newLocation) {
// JW: conditional repaint not working?
// component.repaint();
if (oldLocation != null) {
Rectangle r = component.getRowBounds(oldLocation.y);
if (r != null) {
r.x = 0;
r.width = component.getWidth();
component.repaint(r);
}
}
if (newLocation != null) {
Rectangle r = component.getRowBounds(newLocation.y);
if (r != null) {
r.x = 0;
r.width = component.getWidth();
component.repaint(r);
}
}
setRolloverCursor(newLocation);
}
代码示例来源:origin: org.swinglabs.swingx/swingx-all
@Override
protected void rollover(Point oldLocation, Point newLocation) {
// JW: conditional repaint not working?
// component.repaint();
if (oldLocation != null) {
Rectangle r = component.getRowBounds(oldLocation.y);
if (r != null) {
r.x = 0;
r.width = component.getWidth();
component.repaint(r);
}
}
if (newLocation != null) {
Rectangle r = component.getRowBounds(newLocation.y);
if (r != null) {
r.x = 0;
r.width = component.getWidth();
component.repaint(r);
}
}
setRolloverCursor(newLocation);
}
代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop
@Override
protected void rollover(Point oldLocation, Point newLocation) {
// JW: conditional repaint not working?
// component.repaint();
if (oldLocation != null) {
Rectangle r = component.getRowBounds(oldLocation.y);
if (r != null) {
r.x = 0;
r.width = component.getWidth();
component.repaint(r);
}
}
if (newLocation != null) {
Rectangle r = component.getRowBounds(newLocation.y);
if (r != null) {
r.x = 0;
r.width = component.getWidth();
component.repaint(r);
}
}
setRolloverCursor(newLocation);
}
代码示例来源:origin: org.java.net.substance/substance
TreePath oldDrop = oldValue.getPath();
Rectangle oldBounds = getPathBounds(tree, oldDrop);
tree.repaint(0, oldBounds.y, tree.getWidth(),
oldBounds.height);
if (newDrop != null) {
Rectangle newBounds = getPathBounds(tree, newDrop);
tree.repaint(0, newBounds.y, tree.getWidth(),
newBounds.height);
代码示例来源:origin: com.github.insubstantial/substance
TreePath oldDrop = oldValue.getPath();
Rectangle oldBounds = getPathBounds(tree, oldDrop);
tree.repaint(0, oldBounds.y, tree.getWidth(),
oldBounds.height);
if (newDrop != null) {
Rectangle newBounds = getPathBounds(tree, newDrop);
tree.repaint(0, newBounds.y, tree.getWidth(),
newBounds.height);
代码示例来源:origin: de.sciss/jtreetable
public boolean editCellAt(int row, int col, EventObject e) {
if (super.editCellAt(row, col, e)) {
if (col == treeTable.getHierarchicalColumn()) {
Rectangle b = tree.getRowBounds(row);
b.x = 0;
b.width = tree.getWidth();
tree.repaint(b);
}
return true;
}
return false;
// return super.editCellAt(row, col, e);
}
代码示例来源: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
protected void paintTree(Graphics g) {
Shape clip = g.getClip();
if (tree.getWidth() <= 0 || !clip.intersects(tree.getBounds()))
return;
int x = tree.getX();
int clipX = 0;
int clipW = tree.getWidth();
if (header != null) {
TableColumn dc = header.getDraggedColumn();
clipX = dragX1 - x;
clipW -= clipX;
} else if (x < dragX0 && dragX0 < x+tree.getWidth()) {
clipW -= x + tree.getWidth() - dragX0;
Graphics cg = g.create(x, 0, tree.getWidth(), tree.getHeight());
try {
cg.clipRect(clipX, 0, clipW, tree.getHeight());
代码示例来源:origin: org.java.net.substance/substance
@Override
public Rectangle getPathBounds(JTree tree, TreePath path) {
Rectangle result = super.getPathBounds(tree, path);
if (result != null) {
if (tree.getComponentOrientation().isLeftToRight()) {
result.width = tree.getWidth() - tree.getInsets().right
- result.x;
} else {
int delta = result.x - tree.getInsets().left;
result.x -= delta;
result.width += delta;
}
}
return result;
}
代码示例来源:origin: khuxtable/seaglass
private void repaintDropLocation(JTree.DropLocation loc) {
if (loc == null) {
return;
}
Rectangle r;
if (isDropLine(loc)) {
r = getDropLineRect(loc);
} else {
r = tree.getPathBounds(loc.getPath());
if (r != null) {
r.x = 0;
r.width = tree.getWidth();
}
}
if (r != null) {
tree.repaint(r);
}
}
代码示例来源:origin: khuxtable/seaglass
boolean hasBeenExpanded;
boolean isLeaf;
Rectangle rowBounds = new Rectangle(0, 0, tree.getWidth(), 0);
Rectangle bounds;
TreePath path;
代码示例来源:origin: org.java.net.substance/substance
bounds.y, this.tree.getWidth() - this.tree.getInsets().right
- this.tree.getInsets().left, bounds.height);
if (dropLocation != null && dropLocation.getChildIndex() == -1
SubstanceCoreUtilities.makeNonOpaque(jRenderer, opacity);
this.rendererPane.paintComponent(g2d, renderer, this.tree, bounds.x,
bounds.y, Math.max(this.tree.getWidth()
- this.tree.getInsets().right
- this.tree.getInsets().left - bounds.x, bounds.width),
内容来源于网络,如有侵权,请联系作者删除!