Results 1 to 6 of 6
- 06-24-2008, 04:51 PM #1
Member
- Join Date
- Jun 2008
- Posts
- 7
- Rep Power
- 0
Is there popup search dialog for this?
Hello,
I have a tree that has 2 main parent nodes.
One is called Organizations and the other is called Resources.
Under Organizations node, there are sub-nodes called organization,
and under Resources node, there are sub-nodes called resource.
Each resource can be referred by more than one organization, but it's not easy to know that a resource is referred by what what organization.
What I want to accomplish is ..
If I right click on a resource, there will be popup search dialog that has 2 radio buttons, one is for up and the other one is for down search.
Then, there is find and cancel buttons.
If you click find button, it will high light the first instance of organization that refers this resource depending on up or down radio button you selected.
(up radio button is for top-down search and down radio button is for down-to-top search)
If you click find button again,
it will take you next instance of organization that refers this resource and so on.
If you click cancel button, the search dialog will disappear.
Is there code sample or a way that I can do this?
Should I use JOptionPane?
I really appreciate your help.
- 06-24-2008, 06:52 PM #2
Hi,
i ll tell u how to do,try and come back if stuck up as i am not able to find time to get the ready code or write it for u
1. on click on the node that is in mouselistener, u will have to create and initialize a JDialog
2. Jdialog should have 2 radiobuttons(up and down) and 2 buttoms(find and cancel).
3. On click of findbutton i.e actionlistener of find button first get the radiobutton selected and perform the highlighting in Jtree.
4. To check the if find button is clicked again u can use getClickCount method to perform the 2nd operation of going to next instance
counter=e.getClickCount();
5. On click of cancel button i.e actionlistener of cancel button, exit the dialog
I hope this was useful. I will definitely try to get u the code or links if possibly i get time.To finish sooner, take your own time....
Nivedithaaaa
- 06-26-2008, 03:59 AM #3
Member
- Join Date
- Jun 2008
- Posts
- 7
- Rep Power
- 0
Thanks for your guide.
I think I'm half way, but I have 2 major problem.
I will go without up/down radio buttons, I will do just top-down search.
My first problem is that
I don't want my search dialog disappear when I click "ok" button,
because I want if I click ok first, then it will search first instance, and
if I click ok again(without having to re-open the search dialog again), it will search the next instance.
I want my search dialog only disappear when I click "cancel" button.
But current my dialog disappears when I click the 'ok' button.
My second problem is that,
I don't know where to put "addMouseListener" to have e.getClickCount();
Belows are my codes.
First I tried to use JOptionPane.
And it didn't work.It only prints ok when I click the ok buttonJava Code:class MenuAction_SearchResource extends MenuAction { public void actionPerformed(ActionEvent e) { // we only allow on a resource if (_node.getName().equals("resource")) { int value = JOptionPane.showConfirmDialog(EditorFrame.getInstance(), "Resource Search", "Resource Search", JOptionPane.OK_CANCEL_OPTION); if (value == JOptionPane.OK_OPTION) { System.out.println("ok"); // select the organization that this resource is being referred addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { int count = e.getClickCount(); System.out.println("count click: " + count); Element resource = _node.getElement(); Element rootElement = _contentPackage.getRootElement(); Namespace ns = rootElement.getNamespace(); Element oranizationsElement = rootElement.getChild("organizations", ns); List oragnizations = new ArrayList(oranizationsElement.getChildren()); // we get organization ListIterator organizationIter = oragnizations.listIterator(); while(organizationIter.hasNext()) { Element organization = (Element)organizationIter.next(); highlightBackReference(organization, resource, ns); } } }); } else if (value == JOptionPane.CANCEL_OPTION) { System.out.println("cancel"); } } } }
So I created JDialog(below codes), but it didn't work either.
What am I doing wrong?Java Code:if (_node.getName().equals("resource")) { final JOptionPane optionPane = new JOptionPane( "Resource Search", JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); final JDialog dialog = new JDialog(EditorFrame.getInstance(), "Search Resource", true); dialog.setContentPane(optionPane); optionPane.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if (dialog.isVisible() && (e.getSource() == optionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY))) { //If you were going to check something //before closing the window, you'd do //it here. dialog.setVisible(false); } } }); dialog.pack(); dialog.setVisible(true); int value = ((Integer)optionPane.getValue()).intValue(); if (value == JOptionPane.OK_OPTION) { System.out.println("ok"); optionPane.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { int count = e.getClickCount(); System.out.println("count click: " + count); // select the organization that this resource is being referred Element resource = _node.getElement(); Element rootElement = _contentPackage.getRootElement(); Namespace ns = rootElement.getNamespace(); Element oranizationsElement = rootElement.getChild("organizations", ns); List oragnizations = new ArrayList(oranizationsElement.getChildren()); // we get organization ListIterator organizationIter = oragnizations.listIterator(); while(organizationIter.hasNext()) { Element organization = (Element)organizationIter.next(); highlightBackReference(organization, resource, ns); } } }); } else if (value == JOptionPane.CANCEL_OPTION) { System.out.println("cancel"); } }
Thanks for your help.
- 06-26-2008, 07:59 AM #4
Hi,
I was telling about a simple ActionListener like the following code:
For more details on ActionListener check google please. :)
Java Code:import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class MainClass extends JPanel { public MainClass() { JButton btn1 = new JButton("Button1"); btn1.addActionListener(new ButtonListener()); add(btn1); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.getContentPane().add(new MainClass()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.setVisible(true); } } class ButtonListener implements ActionListener { ButtonListener() { } public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("Button1")) { System.out.println("Button1 has been clicked"); } } }To finish sooner, take your own time....
Nivedithaaaa
- 06-26-2008, 08:01 AM #5
Hi,
I was telling about a simple ActionListener like the following code:
There is no need of JoptionPane anywhere. Try to take a simple JDialog and 2 buttons manually like the one below.
For more details on ActionListener check google please. :)
Java Code:import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class MainClass extends JPanel { public MainClass() { JButton btn1 = new JButton("Button1"); btn1.addActionListener(new ButtonListener()); add(btn1); } public static void main(String[] args) { JFrame frame = new JFrame(); frame.getContentPane().add(new MainClass()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.setVisible(true); } } class ButtonListener implements ActionListener { ButtonListener() { } public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("Button1")) { System.out.println("Button1 has been clicked"); } } }
Sometimes its nice to be simpler... ;)To finish sooner, take your own time....
Nivedithaaaa
- 06-27-2008, 05:08 PM #6
Member
- Join Date
- Jun 2008
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Java Popup Window & Url Query String Value
By Rivelyn in forum New To JavaReplies: 4Last Post: 01-20-2011, 05:03 AM -
nebie popup script, need to add code.
By lilith2014 in forum New To JavaReplies: 2Last Post: 12-30-2010, 11:09 AM -
how we get popup window in java
By baserohit in forum Advanced JavaReplies: 1Last Post: 03-22-2008, 04:39 AM -
Communicating with JSP and popup
By nilz in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 11-20-2007, 04:29 PM -
Popup in Java
By fernando in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:55 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks