Solved

How to change linestyle in JTree

Posted on 2000-02-14
9
769 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping3 challenge 14 70
base64 decode encode 12 119
Unexpected HttpURLConnection connection behavior 2 86
Java Server Faces parameter pass? 6 39
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

911 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

24 Experts available now in Live!

Get 1:1 Help Now