Select from a UI list and perform an action - java

we're building a small chat app for an assignement in our university. I have a question regarding how I can implement something.
This is our ui. The big white part is a jTabbedPane where conversations the user is participating in will appear. The two small ones are where active groups and active users will appear.
I found out that I can populate a jcombobox from a linkedlist using .toArray. I don't know what ui element to use, in order to display the list elements one under the other, and being "selectable" (only one at a time). The concept is that the user will select a group and press "Join", to, well, join.
This is what I have in my as to how it will look in the end.
Any pointers and advice in general would be greatly appreciated.

It looks like you're wanting to use either a JTable or a JList -- one with a custom renderer, a renderer that displays both the group name and its "status"(?).
If a JTable, then your key job is to create a TableModel that will accept your data well, either by using the DefaultTableModel (the easiest way to do this), or by creating your own model derived from the AbstractTableModel (a little more difficult, but more flexible).
For a more detailed answer, consider providing pertinent code, preferably as a minimal example program or MCVE.

Related

How to implement codes in GUI formed apps in Java swing?

I really have a hard time finding help on internet since no one is giving examples on how to implement codes in GUI formed app. So I have my interface created and whole app works through buttons. Every code I find is for just workspace line, or how would I call it. Now I want do the following:
I have an input page for registering members in the gym. When I register them, they go to jTable. Now, I want to make it possible to edit columns Weight and Instructor from the table. I saw how to add ComboBox into table column, but don't know how do it in GUI formed app, where table is not created by the code. And I want to edit Weight column with jTextField the same I would do with ComboBox for instructors.
The question can also be: How do I define these custom things in table (or any other object in GUI Java App) when I already have GUI table set on place with drag and drop in NetBeans?

How to make a board in Java using 2D arrays and JTable ?

What I have in mind is to make a JTable. The model will use the 2D array's columncount and rowcount to set the JTable's rows and columns.
What I cant figure out is how do I go around making fields for these cells in the table?
Example fields like - Status(boolean), Image etc. So by having these fields I want to edit the cells when the application is running and show the user the updates.
I have tried to make a 2D object and add fields in there. But it doesnt seem to work.
What would be a good way to build this?
I am using swing to build this.
This isn't a very specific question so that limits the answer I can give - from what you want to do, I'd suggest
Making sure you understand how the Model-View-Controller paradigm works in Swing
Looking into the Observer / Observable framework and how it fits in with MVC
Extending some sort of Swing Component to reflect changes in your model.
Once you've covered the above you should find that implementing what you want to do is reasonably trivial, and that you can ask more directed questions that will get better responses.

Java GUI architecture for larger project

I want to make an app, which will work as interface to several servers.
Why: In web iface provided by default (and we cannot change it) are few things we miss, few could be done better and for sure automation of some stuff would make the job easier.
What do I have: almost finished classes for communication with web interface of a server app.
GUI description:
For some kind of version 0.1: text field for username, radio button to select server and one "go" button. Then several (4-12) action buttons to operate on data, 2x text area with results, one label with some text data - I can manage this.
Then I need to view the data - grid MxN which will load the data, expected size: 7-15 columns, usually 10 rows or less, but rarely it can go over 1k (or even more, but I don't need all to be visible to the user in that case).
What I need: simply an advice.
I wish to start with a simple version (and I'm working on that already, but I'm stuck on too many things - 95% cos and absolutely new to GUI and 5% cos I'm new to java).
I've checked many tutorials, but they're all simple.
Real questions:
1) Verify. In MVC controller should handle all user actions - is it done by view's method which is something like button.addActionListener(param); anotherButton.addActionListener(paramp; ...?
1b) I've seen all implemented via one (nested) class, which was then checking source or smth - is that ok? There will be a lots of buttons etc.
2) How to implement the data grid, when I need to take actions on click / dbl click?
4) First row is header, the rest should be scroll able - should it be in the grid or outside (its own grid):
4a) How to make sure header's size (width) will be the same as in data (I don't want to set up straight size)
4b) I failed to create anything scrollable so far, but thats my bad I guess. How to ensure header will hold on a place and the rest can be scrolled?
5) How should be "data update" implemented? I've got JPanel from which I remove grid component and then I make new one and add data into it (simple, but perhapss there is another way). One of first enhancements will be sorting - use the same way I used for new content?
Thanks a lot for any answer, I know this is not very specific, but example I've found are too simple.
I plan a lots of enhancements, but thats in the future and I don't mind to rework GUI/Controller several times, at least, I'll practise, but I don't want to finish one part of the code and realise I've got to rewrite half of a controller and 1/4 of a view to make it possible.
Note: I plan to use this at work as my tool (if things go right, I could make 25-50% of my work by few clicks :-)
So I really mean this).
Note#2: I'm not new to programing, but I've never created GUI (which is why I've got GUI with menu bar with 2 items and 3 components and almost done web-iface connections).
Note#:3 dragable data header, tabbed data view - thats the plan for the future :-)
MVC in Swing is examined here; use nested classes for ease in prototyping and creating an mcve for future questions; as the need arises, nested classes can be promoted to separate classes having package-private access.
Use JTable; its flyweight implementation of renderers is good for organizing data by row and column.
Item three does not exist, but "always remember to translate cell coordinates" if you plan to drag columns or sort rows.
Use a JScrollPane to keep the table header stationary.
Update the TableModel, and the listening view will update itself in response.
If you are interested not only from the event/messaging architecture, but also on handling mouse/keyboard input, hovering detection, widgets, temporary menus, form re-sizing with widget alignment, dragging and dropping etc. I can advice you to look at this question and my answer with helpful resources.

How do I add a different JComboBox to each JTree node?

I have a JTree that I'm filling with skills for a Game Database programme that I'm writing.
There are several categories, and subcategories (actual skills), and then levels skill below that (sometimes). Currently I'm emulating this with one skill class, some options inside, and a few enums, plus a method to check that if the skill is a category (called isCategory). Two other things to note:
Different types of skill behave differently.Some are bought once, other several times, some have options to pick from etc
Different categories contain different skill. For instance The Weapon Skills category has different types of weapons, but the Armour Skills are in a different section.
I've seen a very good example of attaching a ComboBox via a cell renderer to each node in the tree. Here is the example I found.
I understand the above code, but I can't see how to would attach the combo box to a node, and not to the tree? I've read 'How to use Trees', and I've run, and looked at the code for a few of the demos for tree. I can make basic trees, but I find the tutorials a bit obtuse and lacking in enough detail to figure out for myself how to proceed. I've found another example of only rendering leaf nodes as checkboxes, which is much more complex.
Obviously I'd like to combine the two, being able to have different categories able to have different skills and different skills have different levels of proficiency. However the only way I can think of doing so it to have different JComboBoxModels for the different types but I don't know how to do this, and I can't find out how. I've tried to edit the checkbox example to use ComboBoxes, but for the life of me I can't figure it out.
Could someone give me a hint as to what approach to take on this, as I'm new to Java and strugglingto figure out what to do?
You should implement TreeCellRenderer as well as TreeCellEditor. Both should return JComboBox with different model. Which model to choose you should decide in the getTreeCellEditorComponent/getTreeCellRenderingComponent depending on value parameter (the tree node in fact).
Would this be a good place to start?
Conceptually, yes. Both JTable and JTree use the flyweight pattern to render and edit cells/nodes.
This example cites a basic TreeCellRenderer.
This example illustrates a simple TreeCellEditor using the default renderer.
This example shows an Outline view that incorporates features of both JTable and JTree.

How to make an expandable list with Java Swing

I need to make an expandable list using java swing. I will attempt to demonstrate:
Unexpanded:
>[Expand me!]
>[And me!]
Expanded:
|[Expand me!]
>[Expand us too!]
>[Expand us too!]
>[Expand us too!]
>[And me!]
So, when you click on the "Expand me" portion of the list, another lists will drop down, possibly containing more expandable lists. If you were to click on it again, it's "sub-lists" would then retract. Pretty basic. And, as you can see, I am not looking for JComboBox, and I do not think JList can do this. If someone were to point me in the right direction, or give some programming examples, I would be grateful.
Thanks,
MirroredFate
How about using a JTree.
A control that displays a set of hierarchical data as an outline.
You can try using a JTable and put a button in the first column. When the button is clicked you add more data in the rows in between.
update
Something like this:
Or this
I think the first uses a JTree but that the idea.
BTW these two belong to JIDE Soft, check if it is feasible for you to buy a license:
http://www.jidesoft.com/products/grids.htm
Is not trivial to roll you own but is not impossible either.
check for TreeTable or one example or Outline, but with notice, that on official Java (SnOracle) pages any progress died ...,

Categories

Resources