Hyperlinking the content of a Jlist - Java Applet Development

I need some guidance in implementing a hyperlink function inside a Jlist of an applet.
Specifically, I have a Jlist that displays the values retrieved from a c++ hash table --a paralel application. I want to be able to create a hyperlink function within the Jlist content which once clicked, wraps the clicked value into a php script and thus performs a mysql query (ie: the content of Jlist is : "Angelique Kojo" Once clicked on the value, I want to perform a seach inside mysql with key words "Angelique Kojo".)
Any assistance in this area is greatly appreciated.
Edited by: mbarandao on Aug 4, 2010 12:41 PM

Related

how do i invoke a method after i click on JButton in JTable

I created JButton array along with few other data columns in JTable and forwarded the mouse events to it by "convertMouseEvent" of SwingUtilities.Now iam able to transfer the event, but how do i retrieve the clicked button details and that specific row details and call a method appropriately. 
"addMouseListener" to the JButtons, in "mouseClicked" add for example:
System.out.println(((JButton)e.getSource()).getText());Row details: via table.getSelectedRow()
Message was edited by:
Andre_Uhres 
"addMouseListener" to the JButtons, in "mouseClicked"this is not the best approach.
OP, are you using a custom table model? is the action always the same or does it depend on the selected row? 
I have a data entry form with text boxes and table (to represent dynamic data).Initially i load data with database and update table.Ialso have JButtons in table ,on which if i click the corresponding row values must be filled in above text boxes and appropriate updation must be made and the table should be refreshed.I am using a Dafault Table Model and creating table.
Then i thought about adding ActionListener to every button in every row.but i want any other solution by which i get the cordinates of the mouse click and find out the cell in which it is clicked and get details accordingly.Let me know if there is solution.
Also now i am having a problem in updating the table.Its giving me a class cast exception .I am using jtable.getModel().addRow(Vector ); 
but i want any other solution by which i get the cordinates of the
mouse click and find out the cell in which it is clicked Straight from the JTable API:
columnAtPoint(...);
rowAtPoint(...); 
Also now i am having a problem in updating the
table.Its giving me a class cast exception .I am
using jtable.getModel().addRow(Vector );I don't know if this solves the problem, but you should cast the TableModel anyway:
((DefaultTableModel)table.getModel()).addRow(...);EDIT: Here is an interesting link on topic:
http://www.codeguru.com/java/articles/162.shtml
Message was edited by:
Andre_Uhres

Get a component by Component name or other properties

Hi All,
Can you please tell me, how can i access a component within a container by using the particular component name or some other properties?
Lets take an example, i have a JPanel and it contains 20 JCheckBox's (or some other swing components).
I suppose to assign the properties such as setActionCommand and setName for all the components which is to be unique.
As per my knowledge, if i want to get a JCheckBox inside a JPanel using the getName or getActionCommand property then i will loop through all the JCheckBoxes and find out the same.
In JavaScript, we can access a component directly by using {color:#ff0000}_document.getElementByName()_{color} method.
Like the same is't possible to access a component inside a container such this equalent method in java.
So that i can directly point out my JCheckBox.
In my case, i can't able to use the index or point, to find out a JCheckBox from a group of JCheckBoxes.
Thanks in advance.
Sivagururaja. 
When do you want to get a handle on this component? When it is clicked? Then this is easily obtained via getSource for an the proper ActionEvent object. Or when a separate button is clicked? The details here are important. 
As per my knowledge, if i want to get a JCheckBox inside a JPanel using the getName or getActionCommand property then i will loop through all the JCheckBoxes and find out the sameCorrect, that would be 3-4 lines of code.
Why do you think you need to access the check box by its "name"? Usually components are accessed by an event of some kind in which case you can get the component from the event.
If you really just want to access a component by name, then create a HashMap and add you component to it. That way you can access the component with a single line of code rather than by writing the method suggested above.
Edited by: camickr on Jun 18, 2009 12:36 PM
Late again...the phone interrupted me during the answer 
If you need a getElementByName (or maybe getComponentByName) there's nothing that stops you rolling your own. But what makes you think that the JavaScript function doens't use a loop under the covers?
Or you could use my [_SwingUtils_|http://tips4java.wordpress.com/2008/11/13/swing-utils/] class, which has methods getDescendantOfType and getDescendantOfClass which could be useful to you.
db 
Thanks to all,
Actually i am developing a reporting application which contains more than 10 JPanel's and each contains 28-30 JChechBoxex. I am using Derby DB for storing the resultant report. In my table i have two fields, which contains the JCheckBox names and the parent JPanel, which is to be selected by the user.
If the user wants to edit the report, i need to loop through all the components inside a JPanel to find out the corresponding JCheckBox and makes the setSeleted property to true. I thing this is step down my application's performance. Tha's why i need a better solution.
I will try to achieve HashMap mr.camickr. Thanks you mr.DarrylBurk.
Thanks
Sivagururaja.
I thing this is step down my application's performance. Tha's why i need a better solutionYes, it might slow down performance by 1 or 2 milliseconds by doing a linear search.
This is not a concern and you are micro managing your code when you don't have a real problem. 
Thank you mr.camickr,
I know a little java. Obviously this is not an error. But you guide me a better way to do same.
Regards
Sivagururaja.

updating tree values from a buffer received on an ip socket

Hello,
im tryin to acomplish the following task: i've created a fixed tree structure with JTextFields using DefaultCellEditor and i want to update the values in those TextFields with some values that i retrieve from a String buffer, but i cant seem able to figure out how to do this last part...
any tips or code will be greatly apreciated regarding:
- how to do the update of the textfields
- issues that can be generated from refreshing the values too fast
thanx in advance 
im tryin to acomplish the following task: i've created a fixed tree structure with JTextFields using DefaultCellEditorDo you mean you use a JTree, and a DefaultCellEditor as the tree's editor? Or a JTree using a custom subclass of the DefaultCellEditor? Or something else (in particular, I don't see how to use sensibly a DefaultCellEditor for anything else than an editor in a JTree/JTable)?
N.B.: when you're concerned about displaying data in a JTree/JTable (not editing data in-place), you should use a TreeCellRenderer, not an editor.
and i want to update the values in those TextFields with some values that i retrieve from a String buffer, but i cant seem able to figure out how to do this last part...
- how to do the update of the textfieldsAssuming you are indeed using a renderer: you don't update the renderer directly, you update the JTree's TreeModel, and rely on JTree to call the renderer's getTreeCellRendererComponent(..., value,...) method, which as shown, as the relevant value as one of its argument. With DefaultTreeCellRenderer, you don't have anything more to do (the renderer will know to call setText(value.toString()) on the appropriate rendering widget.
- issues that can be generated from refreshing the values too fastNone. The more current issues are to not respect Swing's threading rule (see the [concurrency |http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html] chapter of the Swing tutorial). As the code that reads the value from the socket probably runs out of the EDT (hopefully), it shouldn't update the JTree, TreeModel, or whatever widget, directly: it has to post to the EDT a Runnable that will do the update, using e.g. SwingUtilities.invokeLater(...), or (more elaborate) be a SwingWorker custom subclass. 
i was using a JTree with a custom cell editor class in wich i had created a custom getTreeCellEditorComponent method, this way my textfields would get updated with a current value any time id click on them wich is not what im aiming for
however the renderer may suite my needs in better fashion
what should i use to modify a specific tree child ? i mean object.getUserObject() will retrieve me the selected object, im interested in pointing out the object from the code
Edited by: Maical on Mar 19, 2010 3:16 AM

JList inside a JList (custom list cell renderer)

Hi,
I have the following requirement:
I am working on an upload application using which users can upload multiple files from their system onto the server.
I have implemented a JList (in to which the file to be uploaded is dragged) and a custom ListCellRenderer such that my list item now displays a file name, file size, thumbnail of the file to be uploaded etc.
My next requirement is to add a JList inside this cell item, since the user should be able to add multiple tags (nothing but simple string values) to the individual file being uploaded. I could add a JList inside the cell item, but the JList cannot be operated on. (I cannot select/delete the list items inside this new JList.)
I read through this post: http://forum.java.sun.com/thread.jspa?threadID=615082&messageID=3416134
and understood that the components get rendered into a list item as a string, hence are not clickable.
Hence I need an alternate solution. I cannot use panels as suggested in the above post link, since my app should be able to upload multiple files together - hence the JList is suitable component (each list item as an individual file to be uploaded). Please tell me what should I use to tag files then?
I need some urgent help.. 
have implemented a JList (in to which the file to be uploaded is dragged) and a custom ListCellRenderer such that my list item now displays a file name, file size, thumbnail of the file to be uploaded etc.I would suggest you should be using a JTable for this:
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
since the user should be able to add multiple tags (nothing but simple string values) Then you just add another column to the table to store the tags. 
Hi,
Thanks for the suggestion.
But I cannot change the UI. The list box to accept the tags should not be another column. I need that just below the other file details. i.e. in the same cell.
Please guide. Can I use some other component or can I extend a JList further such that the components inside the list item can be used as they are?
I need to achieve this somehow.. please advise? 
I need further suggestions. 
The easiest way is to "popup" a dialog when the user double clicks on the selected line in the JList. Then you can create a form that edits each field separately. When the dialog is closed you save all the values from your form into the class that is used to renderer each row.

How to reload Parent Window

Hi, I am facing the problem with reloading the Parent window with default values
This is the Senario.
1) loaded Layout with checkboxes and tree selection(tree with checkbox nodes)
2) after selection I save the selection values in one flat file
3) If I want to load the Layout with selection of values whichi is stored in the saved file.
how can i reload the Parent window and set the selection on Parent window. 
Hello,
816712 wrote:
Hi, I am facing the problem with reloading the Parent window with default values
This is the Senario.
1) loaded Layout with checkboxes and tree selection(tree with checkbox nodes)What do you call the "layout"? In the following I assume it is the list of tree branches that are open and of nodes that are selected.
2) after selection I save the selection values in one flat fileWhat do you call the "selection": the fact that the checkboxes are checked/unchecked, or that the corresponding nodes are "selected" (visually highlighted)? Assuming the latter.
3) If I want to load the Layout with selection of values whichi is stored in the saved file.
how can i reload the Parent window and set the selection on Parent window.If you have used theJTree.getSelectionPathes() and stored the resulting TreePath[] to the file, you can use the reloaded TreePath[] and setSelectionPathes(TreePath[]) to restore the selection. That will only work if the objects in your model has a releavnt equals() implementation (lots of pitfalls in TreePath management, I've always found JTree's "path" model unintuitive, but that may be just me).
Note that if you want "automatic expansion" of the branches that contain the "selected" nodes, you have to use thejtree.setExpandsSelectedPaths(true);
Regards,
J. 
Layout means JFrame. I added ListCheckBox and JTree(nodes with check boxes). after selection of a list from ListCheckBox and JTree, I am collecting the selected values from both the components and storing in to a file. I provided one Option like "Load"(JButton). when the Load button clicks values should be read from a saved file and accroding to that i have to set the selection of ListCheckBox and JTree.
If any information missing plase make a qurey. I can give the information. bcz I am new to this site.
Edited by: 816712 on Dec 3, 2010 1:10 AM 
816712 wrote:
Layout means JFrame. I added ListCheckBox and JTree(nodes with check boxes). after selection of a list from ListCheckBox and JTree, I am collecting the selected values from both the components and storing in to a file. I provided one Option like "Load"(JButton). when the Load button clicks values should be read from a saved file and accroding to that i have to set the selection of ListCheckBox and JTree.
If any information missing plase make a qurey. I can give the information. bcz I am new to this site.There wasn't only a question, but also a hint or two in my post - based on false assumptions, so you may probably discard it.
As far as saving the status of the checkboxes in the "ListCheckBox" (presumably, a custom class encapsulating a list of checkboxes), I suggest you design and add a pair of boolean[] getCheckedState()/void setCheckState(boolean[]) methods to it. All you need to do is pass and save/load the array of boolean accordingly.
As far as saving the status of the "checkboxes" in the tree, I suggest you save/load the tree's model.
Regards,
J.
Edited by: jduprez on Dec 3, 2010 12:53 PM
Just noticed you other thread ({thread:id=2137339}). I now suspect your ListCheckBox is a JList that renders checkboxes. then the advice is the same as for the tree: save and load the ListModel of the JList.

Categories

Resources