I have two Jlist in the same class each with DnD drop enable.
The problem is whatever file I DnD from my desktop to the JLists either number of or number 2 will populate ( and appear ) in JList1. Jlist2 accepts the drag and drop but it is like the content is going to Jlist1 automatically.
Any idea on how to solve that ?
Maybe by cleaning your code ;-)
Take a look at the DropTargetListener you created to enable DnD operations. i think that either it
adds elements to list 1 datamodel wherever you drop them
is the same instance for list 1 and list 2, but configured to drop in list 1
Related
I try to develop a java project for kids to develop myself. I'm not expecting a code, just examples or documentations about it.
The project, takes two numbers and two different kind of fruits from combobox and it displays thoso fruits with matching via line.
For example, the kid select 2 and 3 as a number and apple and orange as a fruit. The program shows 2 apples,there will be line among 2 apples and 3 oranges and there will be line among 3 oranges. And the kid(user) can move the fruits via drag and drop.
How can i do that? I dont know even keywords to search on anywhere.Which libraries or methods i have to learn ?
Sorry for bad language
Thanks
the kid select 2 and 3 as a number
two JSpinners for numbers with one SpinnerNumberModel (you can to reduce range)
or two JComboBoxes with integers in the model as the Items (you can to reduce range)
apple and orange as a fruit.
two JComboBoxes with Icon/ImageIcon in the model (see Oracle tutorial for working code example)
or two JLists with Icon/ImageIcon in the model (use the same methods as for JComboBox, Items in JComboBox are in JList)
can move the fruits via drag and drop.
use JList for this idea
put generated fruits as Item to the model for the another JList (horizontal wrap), for DnD to read Oracle tutorial for working code example about DnD between two JList
How can i do that? I dont know even keywords to search on
anywhere.Which libraries or methods i have to learn ?
post an SSCCE, short runnable, compilable in the case that you will have any issue(s) with a.m. points, demostrated your progress
You can use javaFX. It is much more easier to use than swing and have a modern appearance. There is also a scene builder for javaFX. You can directly place combo boxes or lines via this scene builder.
Alright so I'm trying to create a combo box that will update it's contents during runtime except I have no clue how to do this without receiving a bunch of errors. Is there some sort of method that I can use in order to accomplish this? For example, I have a vector that might start out with the name in drawers 1 and 2 be hi and bye. Then during runtime the program will change drawer one and two to eggs, sausage and add a third drawer with the name being computer. How can I go about changing the name on a JComboBox during runtime?
You want to clear the combobox of all entries using removeAllItems(), then re-add the items from the Vector using addItem().
The data shown in the ComboBox actually lives in its model - some subclass of ComboBoxModel.
DefaultComboBoxModel has methods for adding and removing elements. If you want to completely replace the combo box's contents at runtime, the simplest way might be to just build a new model and call theComboBox.setModel(theNewModel) with it. Also see setSelectedItem() for setting the selection.
I've been trying to freshen up on my Java knowledge and I've been building a small GUI program and I've been running into a bit of a problem.
Basically, I have a JList which I'm currently populating with strings from an object from one of my classes which implement AbstractListModel which we can call my ItemList class. It contains an ArrayList of objects of the type Item which implements Serializable.
But, what I'd like to do is rather than populate my JList with a bunch of strings I'd like to populate it with some kind of string + JTextField combination so I can see one property of each Item object while also being able to update another property by changing the JTextField.
Now, what I'm looking for is the simplest possible way of doing this, and I am assuming there is a (relatively) simple way to do this since it's such a common thing to want to do in a GUI application (although I wouldn't put it past Java and Swing to make it convoluted and complicated).
So, what is the correct way of doing this?
No need to ever use String objects. Instead:
Put Item objects in the JList.
Add a ListCellRenderer to the list, to show the Item object the most user friendly way.
When the user selects an item, show the details in a different place (I'm thinking a panel with 2 columns of labels and text fields, and two rows - one for each attribute, and perhaps a button to Save)
The edit controls would best be encapsulated in a panel that can then hidden when not required, & put in a variety of places, e.g.
Below the list
In the main part of the GUI
displayed in a JOptionPane or a (modal or not) JDialog
Here is an example of placing the 'view/edit panel' (the file details) below the selection component (the table).
I am trying to filter a list that is placed into a listview through the use of 2 drop down boxes.
The first dropdown box is titled price and the second is owner.
I want to be able to select a value in one or more of these drop down boxes and then have the List view re-render with the filtered results.
The trouble is I do not know how to begin this task, would someone be so kind as to enlighten me :D
Thanks in advance!
Your best starting point is probably this example: (Source code also available on this page, ChoicePage.java is the name)
First of all, you have to use a dynamic model in your ListView that generates the list of items depending on what you had selected in the dropdown boxes.
Then the basic idea is that you add an AjaxFormComponentUpdatingBehavior to the components that control the updates (your two dropdown boxes in your case), and in the onUpdate() method of this behaviour you should add the component you want to update to that AjaxRequestTarget passed.
HI All,
I am desperately looking for the assistance on adding and removing the fields and rows using JSF. I am using ICE Faces for the rich UI look. The following is my problem:
I have to add one text box and two buttons (+) and (-) in a row.
When user clicks on the + button, one new row should be added with the above components.
When user clicks on the - button, the corresponding row should be removed from the display.
I am able to add the individual components like text box and remove it. But, here my challenging point is to add and remove as a row. How would I remove that specific row (instance) from the UI View Root.
I have tried several times, but till now I could not find a solution. Please suggest me the possible solutions.
Thanks in advance,
Krishna
Rather use a h:dataTable (or the IceFaces equivalent ice:dataTable) which is backed by a List<Data> contining objects which each represents the data of a single row. On Add just add a new Data item to the list. On Remove just remove the selected Data item from the list.
See also:
How to dynamically add new row to table? - detailed answer to similar question
Using Datatables - shows step by step how to use datatables in JSF 1.x.
CRUD datatable using #ViewScoped - simple example of JSF 2.0 CRUD