Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-24-2008, 06:51 PM
Member
 
Join Date: Jun 2008
Posts: 7
lmsook10 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-24-2008, 08:52 PM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 299
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-26-2008, 05:59 AM
Member
 
Join Date: Jun 2008
Posts: 7
lmsook10 is on a distinguished road
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.

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"); } } } }
And it didn't work.It only prints ok when I click the ok button

So I created JDialog(below codes), but it didn't work either.

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"); } }
What am I doing wrong?

Thanks for your help.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-26-2008, 09:59 AM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 299
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
Hi,
I was telling about a simple ActionListener like the following code:

For more details on ActionListener check google please.
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
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-26-2008, 10:01 AM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 299
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
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.

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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-27-2008, 07:08 PM
Member
 
Join Date: Jun 2008
Posts: 7
lmsook10 is on a distinguished road
Thanks for your help.
I fixed my codes following your advice, and it's working!!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
nebie popup script, need to add code. lilith2014 New To Java 1 04-30-2008 12:44 PM
how we get popup window in java baserohit Advanced Java 1 03-22-2008 06:39 AM
Communicating with JSP and popup nilz JavaServer Pages (JSP) and JSTL 0 11-20-2007 06:29 PM
Popup in Java fernando New To Java 1 08-07-2007 08:55 AM
Java Popup Window & Url Query String Value Rivelyn New To Java 1 06-29-2007 12:48 AM


All times are GMT +3. The time now is 03:29 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org