Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Liutauras Vilda
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Devaka Cooray
Paul Clapham
Saloon Keepers:
Scott Selikoff
Tim Holloway
Piet Souris
Mikalai Zaikin
Frits Walraven
Bartenders:
Stephan van Hulst
Carey Brown
Forum:
Swing / AWT / SWT
how to set JTree line thickness?
Matt Wilcko
Ranch Hand
Posts: 65
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Anyone know how to set the thickness of lines that connect nodes in a JTree? By default, it is only one pixel. I need something a little thicker.
Craig Wood
Ranch Hand
Posts: 1535
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicTreeUI; import javax.swing.tree.*; public class TreeTest { public TreeTest() { JTree tree = getTree(); tree.setUI(new CustomTreeUI()); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(tree)); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } private JTree getTree() { String[] birds = { // branches |<-- child leaf nodes -->| "hawks", "gray", "red-tailed", "rough-legged", "falcons", "harrier", "kestrel", "kite", "owls", "barred", "saw-whet", "snowy" }; DefaultMutableTreeNode root = new DefaultMutableTreeNode("birds"); DefaultMutableTreeNode[] nodes = new DefaultMutableTreeNode[birds.length]; for(int j = 0; j < nodes.length; j++) nodes[j] = new DefaultMutableTreeNode(birds[j]); for(int j = 0; j < 9; j += 4) { root.insert(nodes[j], j % 3); for(int k = j + 1; k < j + 4; k++) nodes[j].insert(nodes[k], k - j - 1); } DefaultTreeModel model = new DefaultTreeModel(root); return new JTree(model); } public static void main(String[] args) { new TreeTest(); } } class CustomTreeUI extends BasicTreeUI { public CustomTreeUI() { super(); } public static ComponentUI createUI(JComponent x) { return new CustomTreeUI(); } public void paint(Graphics g, JComponent c) { Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setStroke(new BasicStroke(3f)); super.paint(g, c); } }
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
JTree
JTree
JTree
JTree
JTree
More...