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.
Related
I want to run the example from the official Vaadin vendor site:
https://vaadin.com/components/vaadin-grid/java-examples/drag-and-drop
Of course, I have some other objects to drag, but i am happy when the example is working. At the minute, I don't know how it is meant to be used, or I am getting dumb, because I am living in germany.
I wonder why the example is not running out of the box.
When i use this code, there are several errors in the code. What is dragItems? And how to calculate the index of the drop position? Any help is appreciated. I just want to use this framework, but the demos are not compiling.
I want to drag an item from a grid on another grid. How to do that?
These fields are missing in the code:
private Collection<Person> draggedItems;
private Person draggedItem;
private Grid<Person> dragSource;
You can check the full code here for Vaadin 14: https://github.com/vaadin/vaadin-grid-flow/blob/4.3/vaadin-grid-flow-demo/src/main/java/com/vaadin/flow/component/grid/demo/GridDemo.java#L2375
draggedItems is the list of items that you started to drag (they are set on GridDragStartEvent and cleaned on GridDragEndEvent)
You are dropping the items on an item (before or after). The index of the position has to be calculated. It depends if you are using a listDataProvider or something else.
I am trying to make a "Oregon Trail" like game with JAVA for my Computer Science class. It's all going well so far, but I would like some suggestions on ways of doing the following:
The words at the bottom "Health", "Stats", etc are buttons. I was wondering what the best way of making those buttons present information would be. Is there a way I could show them in that information in one of the bottom squares, and when a different button is clicked change the info to that one? Or would it be best to have popup frames to display the information?
IMHO, I'd go with display the content or info of the button in the panels above.
It keeps the information together in a single place and generally makes it easier to manage, no disappearing windows behind other windows for example.
You have any number of options depending on the information you want to display. You could simply use a none editable JTextArea if the information is just text, or a JList if you want to list items if the data is more structured, a JTable and even a JTree if you want to group the data into some kind of groupable hierarchy.
You could use combinations of each, based on your needs
I have a task to create java tree, with three columns: Sport name, Count of sports which are in sport category, and last update. Something similar is dispayed on image bellow:
As you can see, there are 4 kinds of sports: Water, Ball, Skying, Dancing. When I expand skying, there are 3 sports of its kind.
But how to make columns. I can make JTree with nodes and stuff, but how to add columns?
Here is a good example for using a Tree with multiple columns. It looks like this:
I would however suggest using a JFace TreeViewer. There are good tutorials here and here.
It sounds like you want a view that expands like a tree but has rows & columns like a table. Consider Outline, cited here.
I'm writing a Java Desktop utility in Java swing and have a minimal GUI part in it, most of work is done on server side i.e. backend. So, I don't want to spend a lot of time on GUI part, learning different controls and widgets. The problem is that Swing has two controls for (to me)same tasks i.e. dropdown menu and they are JComboBox and JSpinner I don't know the difference and I don't want any limitation that would hinder me from completing my task after I've selected one.
I've to use dropdown to display List<String> returned from DataBase and it can have as many as thousands of values. To keep user from scrolling I'll be taking starting alphabet as input or some category limitation will be there so, it may be that I'll be using specific values to be displayed from List<String>. i want my program to be as efficient as it can be and spend least time on front end as there are a lot of operations on backend.
Any Help will be highly appreciated
you issue talking about AutoComplete JComboBox / JTextField
with some effort could be aplied (AutoComplete JTextField) to JSpinner too
I've to use dropdown to display List returned from DataBase and it can have as many as thousands of values.
all above mentioned JComponents are based on premature array, maybe need to convert java.util.List to String[] or Vector (depends of your code logics)
none of GUI are designated to helt the thousands of values, have look at Paginations for Databases engine
above mentioned AutoComplete JComboBox / JTextField works without any issue up-to 2k rows on todays PCs
for searching or selections from largiest arrays you have look at Stepped JComboBox (about two or more JComboBoxes)
1.st for reduced selection from [0-9, A-Z]
2.nd for searching in records started with A (for example)
redirect Database events to the background tasks and to use SwingWorker or Runnable#Thread
The key difference lies in the model: a SpinnerModel implementation creates a sequence of values, while a ComboBoxModel does not. If objects in a SpinnerModel do not have a suitable natural order, you'll need to impose one.
As practical matter, "thousands of values" will benefit from an auxiliary approach, as suggested in #mKorbel's answer.
JComboBox suits your requirement. JComboBox is suitable for displaying a list of values. JSpinner is used when you want to do some functionality like incerement/decrement on the Spinner's text field.
This Oracle tutorial explains about JSpinner and its similarities to JComboBox. There is a demo app also.
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).