Solved

How to change linestyle in JTree

Posted on 2000-02-14
9
767 Views
Last Modified: 2012-05-04
How can I change the linestyle from dotted to solid in the swing component JTree ?
0
Comment
Question by:eeks2
  • 6
  • 3
9 Comments
 
LVL 7

Expert Comment

by:vladi21
ID: 2526486
0
 
LVL 7

Expert Comment

by:vladi21
ID: 2526496
http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html
By default, the Java Look & Feel draws no lines between nodes. By setting the JTree.lineStyle client property of a tree, you can specify a different convention. For example, to request that the Java Look & Feel use horizontal lines to group nodes (as shown in the next figure), use the following code:

tree.putClientProperty("JTree.lineStyle", "Horizontal");


To specify that the Java Look & Feel should draw lines detailing the relationships between nodes (as shown in the next figure), use this code:
tree.putClientProperty("JTree.lineStyle", "Angled");

---
also look at Swing sources and examples

0
 
LVL 7

Expert Comment

by:vladi21
ID: 2526516
0
 

Author Comment

by:eeks2
ID: 2526597
I know the examples, and I tried it, but on my machine this code has no effect. Lines are always dotted. Even if the code would work, I have only the choice between "None","Horizontal" and "Angled" but this is not what I want, because I want "solid angled" lines.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 7

Expert Comment

by:vladi21
ID: 2526922
Answer : you have only 3 choices,
but You can implement custom UI, i.e. you can extends javax\swing\plaf\metal\MetalTreeUI.java
0
 

Author Comment

by:eeks2
ID: 2530130
When I exchange JTree with MetalTreeUI then I get a lot of errormessages, so I have to reconfigure my whole program. I dont know the difference between JTree and MetalTreeUI, but they seem to use different methods.
0
 
LVL 7

Expert Comment

by:vladi21
ID: 2530898
post ur code
0
 
LVL 7

Accepted Solution

by:
vladi21 earned 200 total points
ID: 2530937
U must do something like this:

create class

class MyTreeUI extends MetalTreeUI {//or  BasicTreeU

ovveride 2 methods of BasicTreeU - look at sources

protected void paintVerticalPartOfLeg()
protected void paintHorizontalPartOfLeg()

}


JTree myTree=new JTree();

myTree.setUI(new MyTreeUI());
0
 

Author Comment

by:eeks2
ID: 2541676
Ok, this basically works. Interestingly I get only the paintHorizontalPartOfLeg event. I filled in following lines.
g.drawLine((int)bounds.getX()-12,(int)bounds.getY(),(int)bounds.getX()-12,(int)bounds.getY()+(int)bounds.getHeight()/2); //vertical part
g.drawLine((int)bounds.getX()-12,(int)bounds.getY()+bounds.getHeight()/2,(int)bounds.getX()-4,(int)bounds.getY()+(int)bounds.getHeight()/2); //horizontal part
Using this code I get solid lines.
Thank You Vladi for suggesting me hints to solve this question.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now