Discussions
Categories
- 196.9K All Categories
- 2.2K Data
- 239 Big Data Appliance
- 1.9K Data Science
- 450.3K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 545 SQLcl
- 4K SQL Developer Data Modeler
- 187K SQL & PL/SQL
- 21.3K SQL Developer
- 295.9K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.6K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 155 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 440 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
Hide horizontal and vertical lines in a JTree
Hi,
suppose we have three JTrees in a Windows L&F where the second one shall not show any vertical or horizontal lines for a node. If this restriction would be true for all three JTrees one could invoke
However only the second one must not show any lines. I tried something like
Does anyone have a clue to solve this problem?
Thx.
suppose we have three JTrees in a Windows L&F where the second one shall not show any vertical or horizontal lines for a node. If this restriction would be true for all three JTrees one could invoke
UIManager.put("Tree.paintLines", Boolean.FALSE).
However only the second one must not show any lines. I tried something like
tree.putClientProperty("Tree.paintLines", Boolean.FALSE); tree.updateUI();But unfortunately this does not work as the lines are still shown. Furthermore we need to set "on/off" the lines dynamically dependend on the user data.
Does anyone have a clue to solve this problem?
Thx.
Comments
-
-> Does anyone have a clue to solve this problem?
Take a look at the source code to see what that particular property does. Then maybe you will be able to override the UI to provide an on/off switch at a table level somehow. -
set your own UI, overriding these (to do nothing)
paintHorizontalLine(..)
paintVerticalLine(..) -
Try with
tree.putClientProperty("JTree.lineStyle", "None");
Bye. -
JTree.lineStyle
only works on metal l&f.
To override the UI should work but it is very ugly to set the ui each time the user changed the data. Beside this imagine your code will be excuted on a windows, linux and mac os.
Do I really have to create my own UI for each l&f just to hide the lines for a node? Is there no other way? -
only tested on windows, but this seems simple enough
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.tree.*; class Testing { boolean showLines = false; public void buildGUI() { JButton btn = new JButton("Show/Hide Lines"); final JTree tree = new JTree(); tree.setUI(new javax.swing.plaf.basic.BasicTreeUI(){ protected void paintHorizontalLine(Graphics g,JComponent c,int y,int left,int right){ if(showLines) super.paintHorizontalLine(g,c,y,left,right); } protected void paintVerticalLine(Graphics g,JComponent c,int x,int top,int bottom){ if(showLines) super.paintVerticalLine(g,c,x,top,bottom); } }); JFrame f = new JFrame(); f.getContentPane().add(new JScrollPane(tree),BorderLayout.CENTER); f.getContentPane().add(btn,BorderLayout.SOUTH); f.setSize(200,200); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); btn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ showLines = !showLines; tree.repaint(); } }); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable(){ public void run(){ try{UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");}catch(Exception e){} new Testing().buildGUI(); } }); } }
This discussion has been closed.