How to show only all children of selected node in JTree??
Dear friends:
I have Two Panels, PA and PB,
PA has a Jtree as code below, and PB listens to PA,
I hope to do following,
If I select a node called A in PA, then Node A's all children such as A1, A2, A3 will be displayed in PB, but not display A1, A2, A3's children such as A3 has C1, C2, C3, C4 & C5, until I select A3 then PB will display only all A3's children: C1, C2, C3, C4 & C5;
i.e, only populate each ONE level of children of Node A or any node I select, not its grandchildren and its grand-grand children;
Please help how to do it??
I tried amny times, failed.
Thanks
[1]. PA panel code:
package com.atest;
import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Enumeration;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
public class DefaultMutableTreeMain extends JPanel {
protected DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options");
protected DefaultMutableTreeNode selectedNode = null;
protected final JTree tree;
protected final JTextField jtf;
protected Enumeration vEnum = null;
private TreeModel m;
protected DefaultMutableTreeNode getDefaultMutableTreeNode() {
//textArea.getText();
return selectedNode;
protected DefaultMutableTreeNode setDefaultMutableTreeNode(DefaultMutableTreeNode tt) {
//textArea.getText();
selectedNode = tt;
return selectedNode;
protected TreeModel getJTModel() {
//textArea.getText();
return m;
protected TreeModel setJTModel(TreeModel ta) {
m = ta;
return m;
public DefaultMutableTreeMain() {
setSize(300,300);
setLayout(new BorderLayout());
DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
top.add(a);
DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");
a.add(a1);
DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");
a.add(a2);
DefaultMutableTreeNode a3 = new DefaultMutableTreeNode("A3");
a.add(a3);
DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
top.add(b);
DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1");
b.add(b1);
DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2");
b.add(b2);
DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3");
b.add(b3);
DefaultMutableTreeNode c = new DefaultMutableTreeNode("C");
a3.add(c);
DefaultMutableTreeNode c1 = new DefaultMutableTreeNode("C1");
c.add(c1);
DefaultMutableTreeNode c2 = new DefaultMutableTreeNode("C2");
c.add(c2);
DefaultMutableTreeNode c3 = new DefaultMutableTreeNode("C3");
c.add(c3);
DefaultMutableTreeNode c4 = new DefaultMutableTreeNode("C4");
c.add(c4);
DefaultMutableTreeNode c5 = new DefaultMutableTreeNode("C5");
c.add(c5);
tree = new JTree(top);
JScrollPane jsp = new JScrollPane(tree);
jsp.setPreferredSize(new Dimension(400,300));
add(jsp, BorderLayout.CENTER);
jtf = new JTextField("", 20);
add(jtf, BorderLayout.SOUTH);
tree.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me) {
TreePath path = tree.getSelectionPath();
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)path.getLastPathComponent();
TreePath tp = tree.getPathForLocation(me.getX(), me.getY());
setDefaultMutableTreeNode(selectedNode);
System.out.println("Current node selected is (tp.toString()=" + tp.toString());
System.out.println("Current node selected is getDefaultMutableTreeNode()=" + getDefaultMutableTreeNode());
if (tp != null){
jtf.setText(tp.toString());
System.out.println("It Has Children as selectedNode.getChildCount()= " + selectedNode.getChildCount());
Enumeration vEnum = selectedNode.children();
int i = 0;
while(vEnum.hasMoreElements()){
System.out.println("2 selectedNode = " + path.toString() + " has " + i++ + " Children in vEnum.nextElement(" + i + ") = " + vEnum.nextElement());
else
jtf.setText("");
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new DefaultMutableTreeMain());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setVisible(true);
}[2]. PB Panel code
package com.atest;
import java.awt.BorderLayout;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.JPanel;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.*;
import javax.swing.JButton;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
public class DefaultMutableTreeSub extends JPanel implements java.io.Serializable{
private JButton removeButton;
private JButton addButton;
JTree tree;
private TreeModel m;
protected TreeDragSource ds;
protected TreeDropTarget dt;
protected TreeModel getJTModel() {
//textArea.getText();
return m;
protected TreeModel setJTModel(TreeModel ta) {
m = ta;
return m;
protected DefaultTreeModel model;
protected DefaultMutableTreeNode rootNode;
DefaultMutableTreeMain dmm = null;
JPanel inputPanel = new JPanel();
public JPanel SLTreeDNDEditableDynamic(DefaultMutableTreeMain tdnd ) {
//super("Rearrangeable Tree");
setSize(400,450);
dmm = tdnd;
setLayout(new BorderLayout());
inputPanel.setLayout(new BorderLayout());
JPanel outputPanel = new JPanel();
System.out.println("Sub selectedNode tdnd= " + tdnd);
tdnd.tree.addTreeSelectionListener(new TreeSelectionListener(){
public void valueChanged(TreeSelectionEvent evt){
TreePath[] paths = evt.getPaths();
TreePath path = dmm.tree.getSelectionPath();
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)path.getLastPathComponent();
DefaultMutableTreeNode itemNode = dmm.getDefaultMutableTreeNode();
System.out.println("Sub node selected is dmm.getDefaultMutableTreeNode()=" + dmm.getDefaultMutableTreeNode());
model = new DefaultTreeModel(itemNode);
tree = new JTree(model);
System.out.println("Sub selectedNode paths= " + paths);
System.out.println("Sub selectedNode path= " + path);
System.out.println("Sub selectedNode = " + selectedNode);
System.out.println("Sub itemNode = " + itemNode);
tree.putClientProperty("JTree.lineStyle", "Angled");
tree.setRootVisible(true);
inputPanel.add(new JScrollPane(tree),BorderLayout.CENTER);
return inputPanel;
public DefaultMutableTreeSub() {
super();
}thanks
sunny
Thanks so much, I use your code and import followig:
import java.util.ArrayList;
import java.awt.List;
but
private static List<Object> getChildNodes(JTree j) {
Object parent = j.getLastSelectedPathComponent();
int childNodeCount = j.getModel().getChildCount(parent);
List<Object> results = new ArrayList()<Object>;
for (i = 0; i < childNodeCount; i++) {
results.add(parent, i);
return results;
here List<Object> and ArrayList()<Object> show red,
Is my JDK version problem??
my one is JKD
C:\temp\swing>java -version
java version "1.4.2_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_08-b03)
Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)
Error as follows:
C:\temp\swing>javac DefaultMutableTreeSub.java
DefaultMutableTreeSub.java:38: <identifier> expected
private static List<Object> getChildNodes(JTree j) {
^
1 error
any idea??
Thanks
Similar Messages
-
How to show only key in mdx query
Hello Experts
i have mdx query such as :
SELECT
[Measures].MEMBERS ON AXIS(0) ,
NON EMPTY [ZCHANNEL].members
Properties [ZCHANNEL].[2ZCHANNEL]
ON AXIS(1)
FROM ZIC_TPL/ZIC_TPL_DETAIL
SAP VARIABLES
[ZVSOCALM] INCLUDING [0CALMONTH].[200605]
the result from this query are zchannel text and zchannel key
how to show only zchannel key ?
really appreciate your help.
regards
JeiMing
Message was edited by: JeiMing TjiamHi Juice
Yes, i have already tried setting zchannel as key only in my query
but the result from mdx query still shown key and text
Regards
JeiMing -
How to show only date in BO webi 3.1 text box
how to show only date in BO webi 3.1 text box for e.g:-
01/01/2005 (no time only date)hi,
just check by which format your date is coming
just create a one variable and check =UserResponse("Transaction Date From (mm/dd/yy)")
if your output is in format of("mm/dd/yyyy hh:mm:ss a")
then some format we have to write in todate syntax
then your final formula for date would be
=FormatDate(ToDate(UserResponse("Transaction Date From (mm/dd/yy)");"mm/dd/yyyy hh:mm:ss A");"dd/mm/yyyy") -
Calendar list function shows only events for date selected....instead of events for date selected and events forward from that date. Is there a setting change needed? Help!
Hi,
Did you check that your universe object referring "Date of Completion" has Date data type?
Can you also provide the BOE verson you are using?
I remembered that the calendars were not displayed in XIR2 version.
Didier -
Setting custom color for selected node in JTree?
Hi,
i want to set my own color for selected node in JTree. i don't want to set for all the nodes...how to set Color for Selected node using TreeCellRender class?
Thanks
ManiI assume you are not setting a custom tree cell renderer...
javax.swing.JTree theTree = ...;
java.awt.Color newBGColor = ...;
((javax.swing.tree.DefaultTreeCellRenderer)theTree.getCellRenderer())
.setBackgroundSelectionColor(newColor); -
How to show only Indexes in Search Scope
Hi All,
Is it possbile to allow users to choose only Indexed in search scope.
I tried editing the Search Options set, there i found that I can enable and disable search scope, but whn search scope is enabled both the Indexes and folders are visible.
I want to show only Indexes to the user. How can I hide the folder options alone in the search scope?
Thanks and Regards
GeorgeInstead of using the Search Options set in the KM Search iView, use the Search Component Set.
Create your own Search Component Set by going to <b>System Administration > System Configuration > Knowledge management > Content Management > User Interface > Search > Search Components</b>
While creating the Search Component Set, Specify <b>Component for Search Options</b> as <u>search_input_indexes</u>.
This should help you.
Or you could do the following.
In the Search Options set, Do the following.
1) Uncheck <b>Enable Search Scope Selection</b>.
2) Provide the various index names in <b>Search Index IDs (csv)</b>
The above option would by default search the selected indexes for the search term and would not provide the user with the functionality of searching in folders.
Pradeep. -
How to show only one element in drop list(common VO)
Hi All,
I'm using 11g adf jdev.
I have a common view object VO. In this VO one attribute is dropdown list , which i commonly used in some jsf pages .
Now in one particular jsf page i want show only one element in the dropdown list .
how can i handle with out distrib'g the common VO.
THANKS IN ADVANCEBTW, why you want to display only one item in the list.
If you are sure that the list will be having only one item, why don't you have it as inputText/outputText
How do you filter out the item to be displayed in the list? If that filtering is done on listdatasource bound to the list, the list will automatically show only one item(i.e, the filtered item)
HTH
Sireesha -
How to show only the wanted member in Journals?
Hi experts,
I would like to know how i can limit the members of one dimension than can be choose when user creates a journal. I mean, i know that it exists the property Enable_JRN than permit show only member with this property to yes of one dimension.
But i would like have limitations for the combination of two dimensions, i mean, for example, if i have selected one member of dimension Account with ID 23456, i want to have the possibility of choose ONLY these flows, F99, F30. But for another member of account with ID 07898, only i want show (and then permit) the flow F35.
Any ideas, about it?
Thank for your help!!!BPC doesn't have a method for this form of dimension combination validation or restriction in the current form. The only option I can think of is to possibly build a second application that contains the valid combinations, noted by using a single value entered at the valid combination. Then using the valdation and Journal Script file to check the validity of the combination of the posted value using script logic or defering to an EVDRE that checks the Validation application during a send of data process, instead of using Journals. We have been requested this behavior in the past to development, but your request as well would be beneficial, via SAP Support.
-
Show only images in the selected folder
Hi All,
It would be nice if I could show only the images in the selected folder without including images in subfolders. For example a check box next to the folder name could switch between "selected folder only" and "include subfolders" viewing modes.Un-check Menu/Library/Include Photos from Subitems.
It is already there in V1.1.
Don
Don Ricklin, MacBook 1.83Ghz Duo 2 Core running 10.4.10 & Win XP, Pentax *ist D
http://donricklin.blogspot.com/ -
How to show only the result of a query
Hi experts,
i need to show only the result of a query (hiding all the rows)
according to mathematical functions like sum, average, count ets. i need the result to be shown widhwise the query (Horizontal)
thanks a lot
NirHi
I did get exactly.....but if i m right then you can do this by selecting the keyfigure goto the calculation tab select calculate result as sum or whatever you want to use.
Regards
Lalit k Tyagi -
How I show only 20 rows per pages in a rtf report in BI Publisher 11g
I'm making a report and i want show only 20 rows per pages in a formatt RTF. I get this with anything as a xls, xslt....
I'm a new user....please . Any idea..???
Thank for all.
Edited by: 844565 on Mar 15, 2011 7:34 AMInstead of doing that take the url CURRENT_SERVER_URL(pre-definde BI Publsiher variable) by declaring like below
<?param@begin:CURRENT_SERVER_URL?>
Then subsequently add the extra patameters eg. region like below
{$CURRENT_SERVER_URL}Data/Country.xdo&p_region={REGION} <- get this REGION value from XML
Cheers,
ND
Use the "helpful" or "correct" buttons to award points to replies. -
How to show only six values in dropdown box in design studio 1.3
Hi,
There was an requirement from our client to show only last six months in the drop down, when actually there is almost past 30 months are coming from the database. The data format also looks similar to "2014007", "2014006:..etc. Any idea to achieve this through loop.?
Thank You,
PalaniHi Karol,
I like your idea, but i have difficulties to use it
i have a datasource DS_2 and i just want to show specific Members of my keyfigures.
When i fill my dropdown with this code it just gets empty and returns an error. Somehow i have to say if i want to show the Key or Text ?
i also need this infiormation to be able to compare my elements in the if clause ?!
Can you help me out ?
Best regards
Manfred
DS_2.getMembers("003N81FHQ23D64UTALOPW7MVN",0).forEach(function(element, index) {
DROPDOWN_2.addItem(index, element);
/* if ((element == value1) || (expression2 == value2)) {
if_statements
} else {
else_statements
EDIT ....
I've found the way how to access the keys and values ... i have to define an array and then i am able to access the internal keys and Text.
Just for others searching ....
var ArrayMem = DS_2.getMembers("003N81FHQ23D64UTALOPW7MVN",0);
DROPDOWN_2.addItem("#", "No Filter");
ArrayMem.forEach(function(element, index) {
if ((element.text == "Anzahl Sätze") || (element.text == "Gepäckgewicht")) {
DROPDOWN_2.addItem(element.internalKey, element.internalKey + " - " + element.text);
This SCN article helped me out: http://scn.sap.com/community/businessobjects-design-studio/blog/2014/09/19/learn-about-arrays-in-design-studio-13
Best regards
Manfred -
How to show image in matrix by selecting matrix column type as "it_PICTURE"
Hi All!
Can i show image in matrix, by selecting matrix column type as "it_PICTURE". If yes please write the steps.
Thanks & Regards
SurojitHi
First you have to set the matrix column type as it_PICTURE then bind that column to a userdatasource or dbdatasource. In the following code I am using userdatasource . This code will set the picture to a sepecified columns first row. Please create small image and paste it in your c drive (15X15 size image-- "c:\pic.png")
Dim oColumn As SAPbouiCOM.Column
Dim mtxDisp As SAPbouiCOM.Matrix = form.Items.Item("mtxDisp").Specific
form.DataSources.UserDataSources.Add("udsPic", BoDataType.dt_SHORT_TEXT, 254)
oColumn = mtxDisp.Columns.Item("colPic")
oColumn.DataBind.SetBound(True, "", "udsPic")
mtxDisp.AddRow()
mtxDisp.GetLineData(1) '*Loads UserDataSources from line X*'
mtxDisp.DataSources.UserDataSources("udsPic").ValueEx = "c:\pic.png"
mtxDisp.SetLineData(1) '*Sets Matrix line X based on current UserDataSource values*'
Hope this helps
Regards
Arun -
How to show only the result line of a Query result ?
Hi Experts,
I want to show only the result line of the Query. Is this possible in query Designer ?
In BeX Workbook, I can hide the rows but they grow or shrink dynamically and hence it is unpredictable how many rows to suppress.
If you have any solutions/workarounds, please reply !
RekhaVBA coding can be used to display just the Result rows.
Somthing like this - modify as needed.
This scans the range of query results looking to find the last row, then checks those rows to see if the word Result is found or not, deleting (or you could just hide) the detail rows. There is also a LEAF option in BEx Boolean options that returns a 1 or 0 depending on whether a row is a detail or result that could also be used to hide rows rather than looking for the presence of "Result" in a particular column
Sub SAPBEXonRefresh(queryID As String, resultArea As Range)
For rownum = 17 To 64000 Step 1
' col 2 is the Total Result, col 3 is the User Group result
If Cells(rownum, 2) = "" And Cells(rownum, 3) = "" Then
lastrow = rownum - 1
Exit For
End If
Next
For rownum = lastrow To 17 Step -1
If Cells(rownum, 2) = "Result" Or Cells(rownum, 3) = "Result" Then
Rows(rownum).Hidden = False
Else
' Rows(rownum).Hidden = True
Rows(rownum).EntireRow.Delete
End If
Next
End Sub -
How to show up all the open Apps in this new iOS 7?
Mine iPad2.
When i was on the previous iOS 6.. I could press on the home button and it will display all the opened up Apps. I could then close what ever Apps I wish to close.
Since updating to the latest iOS 7 I do not get opened up Apps displayed on pressing the devices home button. How could I get my iPad 2 to show up all the opened Apps? Double tap on the home button does not work in this new iOS 7.
Any clues
Your advice would be greatly appreciated.
RegardsThanks so much this works. **** apple. Every time they update one has to learn how to do simple tasks all over. I appreciate you giving me/us the answer. By the way, I hate the new operating system. It ***** on all level. Icons look like they belong in a preschool.
Maybe you are looking for
-
What has APPLE done to iTunes 7.1 This is HORRIBLE
This new version has completly jumbled all of my TV shows and will not put them back in numerical or in episode order. What is the problem here, does Apple think people just want to watch any old thing that comes up next on the computer. Help ...plea
-
Project won't open but others will in GB.. HELP PLEASE! MISSION IMPOSSIBLE
Hello people: I think this will be the most difficult task to solve or maybe fix; if even possible.. Ok so basically i was working on my latest project last nite: a 5 min track with all kinds of midi and real instrument channels, effects and AU, VST
-
Is anyone else having these problems? - How do I get past this 'glitch' in the system? - Account is valid, password is valid, iTunes appears to be accessing the store when these 'security procedures' commence and then access to store stops and timed
-
ME_PROCESSPO_CUST-GET_HEADER get items? get accounting?
I am using BADI IF_EX_ME_PROCESS_PO_CUST to perform custom processing for P.O.s. In one scenario the only method that gets broken into is "GET_HEADER". I have the code below activated so far. My lack of OO knowledge is handicapping me. Ihaven't seemd
-
Additional fields in ME2L/ME2M/ME2N
Is there any standard way to add additional fields in output of standard Purchasing reports like ME2L/ME2M/ME2N. Dont want to copy the same in Zprogram and do the modifications. Few sites talk about T-code OMEM but since working on SAP version 4.7 wh