Solved

How to change linestyle in JTree

Posted on 2000-02-14
9
771 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

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
 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
object oriented programming comparison 5 72
reverse digits of a number using for loop 5 46
Opening PDF on button click and fill new document 2 39
servlet example 17 33
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)
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

831 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