JTree - Mutiple Selection
Hi
I have a JTree and whan to enable mutiple selection i.e. the user holds down the CTRL key and selects as many item as s/he wishes. I tried the follow piece of code but it did not work.
jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
Any suggestions
Thanks in advance
Bernie-wolf
Hi,
Well, that is the way that you should set the selection model, and the code does work, so there must be something else going on I would guess.
What exactly is it doing, and what do you expect it to do?
If you could post a small code snippet that compiles that shows the problem, then people could run it and debug the problem
Cheers
Similar Messages
-
Are mutiple selections possible
I have a Search Page, Result Page and Detail Page working. I
need to be able to allow for mutiple selections on the dynamic
select list box I have on my search page. I can not find any
instructions on how to do this.
I appreciate any tutorials or help anyone can give!
CrystalCDROUSE wrote:
> I have a Search Page, Result Page and Detail Page
working. I need to be able
> to allow for mutiple selections on the dynamic select
list box I have on my
> search page. I can not find any instructions on how to
do this.
>
> I appreciate any tutorials or help anyone can give!
If what you are asking is how to make the list so that you
can selection multiple items, then all you need to do within
Dreamweaver is to select the list (make sure that Type is set to
list, and then check the Allow Multiple box. Or go into the code
for the select tag and add multiple="multiple" in the opening tag
of the select.
If what you are asking is how to handle the multiple
selection on the server side to filter your recordset that is
different and a bit more involved and will require the knowledge of
the server language you're working with (and possibly the database
too).
Danilo Celic
|
http://blog.extensioneering.com/
| WebAssist Extensioneer
| Adobe Community Expert -
I am allowing the user to search for a node in a JTree. I can find the node and progamatically expand and select the node. What I would like to do next is find the x,y coordinates of this selected node so I can use Robot to move the mouse to this node. I have hover help which is chock full of information in HTML describing this node, however, the user now is required to move the cursor to this selected node to see the hover help.
Any help would be appreciated.Hi ,
try this
jlabel.setIcon( null ) ; -
I use the jTree. When an element is selected - i dont like how it looks.
Check the screenshot : there are two selected areas - a standart one (top) and a custom one(bottom), dont pay attention to the gradient.
The designer made an improved variant. As you can see, the selection exceeds the jTree and goes over the JPanel, which comprises the jTree.
How can I make it like this in my app?
P.S.
I have an idea to make a half-transparent JPanel and place it over the tree... but I am not sure about the TRUE-ness of this solution :)I use the jTree. When an element is selected - i dont like how it looks.
Check the screenshot : there are two selected areas - a standart one (top) and a custom one(bottom), dont pay attention to the gradient.
The designer made an improved variant. As you can see, the selection exceeds the jTree and goes over the JPanel, which comprises the jTree.
How can I make it like this in my app?
P.S.
I have an idea to make a half-transparent JPanel and place it over the tree... but I am not sure about the TRUE-ness of this solution :) -
JTree Nimbus selection treeNode
I made a jtree with a custom TreeCellRenderer. The leaf nodes are a jpanel with a checkbox in and JPanel. The problem now is that when you select a tree node, there is a selection color box beside the jpanel.
Here is a sscce:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
public class Users {
private static JFrame frame;
private static JPanel usersPanel;
private JTree usersTree;
public Users(){
usersPanel = new JPanel();
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Gebruikers");
DefaultMutableTreeNode willie = new DefaultMutableTreeNode("Willie");
DefaultMutableTreeNode Anna = new DefaultMutableTreeNode("Anna");
rootNode.add(willie);
rootNode.add(Anna);
usersTree = new JTree(rootNode);
myTreeWithCheckBoxRenderer renderer = new myTreeWithCheckBoxRenderer();
usersTree.setCellRenderer(renderer);
usersTree.setRootVisible(true);
usersTree.setEditable(false);
usersTree.setOpaque(false);
usersPanel.add(usersTree);
class myTreeWithCheckBoxRenderer extends DefaultTreeCellRenderer {
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
JPanel panel;
JCheckBox checkBox;
JLabel label;
public myTreeWithCheckBoxRenderer() {
checkBox = new JCheckBox();
label = new JLabel("Gebruikers");
panel = new JPanel(new BorderLayout());
panel.add(checkBox, BorderLayout.WEST);
panel.add(label, BorderLayout.EAST);
panel.setBackground(Color.red);
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
Component returnValue;
if(!leaf){
renderer.setBackgroundSelectionColor(null);
renderer.setText("Gebruikers");
returnValue = renderer;
else{
if(hasFocus){
panel.setBackground(Color.blue);
returnValue = panel;
return returnValue;
private static void createAndShowGUI(){
new Users();
frame = new JFrame("Tree");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(usersPanel);
frame.pack();
frame.setPreferredSize(new Dimension(800, 600));
frame.setLocationRelativeTo(null);
frame.setVisible(true);
public static void main (String[] args){
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
} catch (UnsupportedLookAndFeelException e) {
// handle exception
} catch (ClassNotFoundException e) {
// handle exception
} catch (InstantiationException e) {
// handle exception
} catch (IllegalAccessException e) {
// handle exception
javax.swing.SwingUtilities.invokeLater(new Runnable(){
@Override
public void run(){
createAndShowGUI();
}I tried using a DefaultTreeCellRenderer and use the setBackgroundSelectionColor() method to null, but it doesn't change anything. Also setting the background of the JPanel to null doesn't make a change when you check with (if(hasFocus)). However I have the impression that nimbus is causing the problem, because if you comment the nimbus part out, you don't have the selection box anymore.
Does anyone has an idea to solve this?
Edited by: Kligham on 30-aug-2010 19:25Kligham wrote:
Thank you very much!You're welcome.
Kligham wrote:
Problem solved. So since this cell background rendering is a Nimbus "feature", can I assume that the "not displaying of angled lines" also is a Nimbus "feature". Since the JTree tutorial says this should do the trick:
usersTree.putClientProperty("JTree.lineStyle", "Angled");So I probably have to override it the same way, so I was wondering how you know what UIDefaults there are?Well, "JTree.lineStyle" is actually a client property and not a UIDefaults property. In other words, "JTree.lineStyle" is on the same logical level as "Nimbus.Overrides". Unfortunately, there is no way to determine which client properties a component or a component UI implementation supports except carefully examining its source code. javax.swing.plaf.synth.SynthTreeUI (the Nimbus TreeUI implementation) doesn't seem to support any client properties. It might be handled somewhere else, though.
As an alternative to using "JTree.lineStyle", you could try to use a backgroundPainter that draws angle lines instead of the "do nothing" painter I suggested.
To determine which UIDefaults properties are available for a given LaF implementation, you can iterate over the UIDefaults' entrySet (UIDefaults is a subclass of Hashtable). For Nimbus specifically, Jasper Potts already did that. See the [corresponding blog entry|http://www.jasperpotts.com/blog/2008/08/nimbus-uimanager-uidefaults/] and [Nimbus UIDefaults Properties List|http://jasperpotts.com/blogfiles/nimbusdefaults/nimbus.html] -
JTree and selected node question
Hello
Is it possible to convert the selected node to an int?
I guess I'm looking for something llike this.
int nodeNumber = node.getSelectedIndex();
There is nothing like that in the API, and it would help greatly if I could find a way do this.
Thanks
Have a good holiday
JimFrom the API for JTree
public int getMinSelectionRow()
Gets the first selected row.
Returns:
an integer designating the first selected row, where 0 is the first row in the display
But I think this is based on how many rows are displayed at the present time and might change if the tree is opened above it. -
JTree - multiple selection doesn't highlight tree nodes
I have a JTree which was working great with single selection of objects within it. Now i'm expanding this to work with multiple selected objects at the same time, but the objects are not visibly highlighted in the tree.
I switched to using DISCONTIGUOUS_TREE_SELECTION, and using setSelectionPaths(TreePath[]) instead of setSelectionPath(TreePath). This works fine, except that the newly selected paths don't visually highlight any more (worked fine with single selection).
I had thought that the RowMapper was the culprit, but the default VariableHeightLayoutCache seems to be in place and ok. What should i be checking to get this to work right?
Thanks./me beats forehead against the desk..
TreePath selectionPath = new TreePath( entityNode.getPath() );
NOT just
TreePath selectionPath = new TreePath( entityNode ); -
I have a JTree on the left scrollpane and on clicking the value of a node, I display the value in a text field on the right scrollpane. I change the value and set the value in the JTree . I am unable to make the edited tree path selected. The methods provided in the API do not seem to work.
Don't the JTree.makeVisible( ... ) or JTree.scrollPathToVisible( ... ) methods help?
kind regards,
Jos
Edited by: JosAH on Aug 23, 2009 6:19 PM: typo -
JTree get selected node/object values
I wan to get all the selected nodes/objects values that I added to the JTree. How can I do this?
Thanks.TreePath[] paths = tree.getSelectedPath();
for(int i = 0; i < paths.length; i++){
TreeNode node = (TreeNode)paths.getLastPathComponent();
Object mySelectedObject = node.getUserObject();
}Some minor Errors
We have to use array paths[i] instead of paths
The correct code as used by me is
javax.swing.tree.TreePath[] paths = jTree1.getSelectionModel().getSelectionPaths();
for(int i = 0; i < paths.length; i++){
javax.swing.tree.TreeNode node = (javax.swing.tree.TreeNode)paths.getLastPathComponent();
System.out.println(((javax.swing.tree.DefaultMutableTreeNode)node).getUserObject());
CSJakharia -
hi guys,
I am developing a jTree for a networking product,which will show all the network elements present in the network.The tree also shows the device status like Up,Down etc.I have provided a button to refresh the jtree to update the status of the devices.But after updating the jtree when i try to expand or setSelected path to previously selected leaf,the jTree is expanding only till the parent of the leaf.Here is the code which i have written:
public void addRootNodes()
TreePath path=jTree.getSelectionPath();
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)path.getLastPathComponent();
TopologyUtilities.getNetworkCollectionDetails();
TopologyUtilities.getRuntimeDataMapOnRefresh();
initializeData();
rootBusiness.removeAllChildren();
rootNetwork.removeAllChildren();
rootDiscovery.removeAllChildren();
addRegionLocationToBusinessView();
AddNodesToTree.addRoutersToNetworkView(configuredNetworkCollection, dataMap, rootNetwork);
AddNodesToTree.addRoutersToDiscoveryView(discoveredNetworkCollection, configuredNetworkCollection, dataMap, rootDiscovery);
treeModel.reload();
panel.removeAll();
jTree.setSelectionPath(path);
Thanks for the help in advance
bye,
SrinivasSince you have a reference to a DefaultMutableTreeNode object, can't you do something like
TreeNode[] nodes = n.getPath();
TreePath path = new TreePath(nodes);
tree.setSelectionPath(path); -
JTree default selection?
I've tried searching for this here and there but nothing turned up...
I was wondering if it is possible to set a default selected item on a JTree.
So that if no nodes are selected - the first item is selected by default.
Any hints would be greatly appreciated, thanks.If for "nested element" you mean "a node", you can use setSelectionPath(TreePath path) and setSelectionPaths(TreePath[] paths).
Message was edited by: java_knight -
Checkbox List & mutiple selection
I've added checkboxes to a list component using the
cellrenderer however the behavior is different from what i expcted.
I'm only able to check one box in the list at a time. I need to be
able to check mutiple boxes in the list.
I'm aware you could hold down the control key and select
individual the checkboxes, but the application i'm developing is a
touch screen aplication hence no keyboard, no control key. I've
tried programmaticaly setting the selectedindicies but the
checkboxes don't appear checked after the selectedindices have been
set.
Any help is appreciated.
©®I'm in the same situation... do you have a solution... or do I go off to reinvent the wheel?
-
How to modify a select option without range and mutiple selection??
hi all,
i need to modify a select option by removing the range and option for multiple entry. i other words i need to make select option as parameter.( because i cannot use parameter in my program due to some constraints.)
is it possible to change the select option as per my requirement if yes please let me know how is it possible.
Thanks in advance.
Sreekanth.hi,
Yes u can use code like following way..
select-options : s_matnr for mara-matnr no-extension no intervals.
Reward if helpful.
Regards
Gagan -
hi
is it possible to have multiple selection screens?
i want to do calculations using a selection screen.
how do i do it?
regards
ArunHi Arun,
Yes, you can have multiple selection screens. Check following link from SAP Help -
http://help.sap.com/saphelp_nw04/helpdata/EN/9f/dba66935c111d1829f0000e829fbfe/content.htm
You can have multiple selection screen using tabs.
SELECTION-SCREEN BEGIN OF TABBED BLOCK...
Here are some examples
http://www.sap-img.com/ge001.htm
http://www.thespot4sap.com/Articles/Create_Subscreen_In_ABAP.asp
Cheers,
Manikandan R -
Hello again,
Can anyone provide some advice on how to implement a drag selection of tree nodes. I don't necassarily need code, just some advice on whats the best practice here. I've been studying how to go about it and my best guess is adding all the mouse listeners to the tree and grabbing coordinate and component width and height info based on mouse released and mouse pressed. Is this the way to do it? Can I use dnd in some way?
Thanks for any help.
ShawnSee if this is of any use http://java.sun.com/products/jfc/tsc/articles/dragndrop/index.html
Maybe you are looking for
-
I had a free trial of Lightroom 5 and tried to purchase it, but page errors blocked me from being able to do this. I then got a free trial of Adobe CC. At first I saw my old photos, then the whole thing went down, and now I have a new Lightroom 5 tr
-
Can't get get_blob_file_src to work in my application
Application is on apex.oracle.com Workspace : partituren username: demo password: ZaGreb_12 application: 32570 collectiebeheer Page 5: Person details. Problem: I have a separate region to display the image which is in P5_PORTRAIT. However: what I see
-
How do i fix blue screen on ipad2
All of a sudden i have a blue screen on my ipad 2. can i fix this myself and how?
-
32 bit EHp1 system export error on Oracle 10.2.0.2 & windows
Hi All, I am performing export of solman EHp1 system base on Oracle 10.2.0.2 & windows 2003(32 bit) bot database & OS). Database size is 100 gig.during export it stope at error. I checked sapinst.log which shows below error INFO[E] 2010-09-16 21:03:2
-
Dear Expert, I have created transaction variant using SHD0 from the original transaction ME22N ( change Purchase order) , my purpose to do this is i want to create new transaction code ZME22N which only the delivery schedule date can be changed, whil