Solved

How to change linestyle in JTree

Posted on 2000-02-14
9
772 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
windows explorer path to command prompt 5 54
tomcat administrtor 12 61
String array comparison 4 38
web project error add remove 1 29
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.

860 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