Java selecting an option when clicking specific position within JScrollPane - java

I have developed a chat room application in Java that allows users to broadcast messages to every online user. I want to develop a new functionality that will allow the user to click on one of the online users in order to have a private chat with him/her. For this purpose I have developed a scroll-able text area that will contain those online users.
I think I could set the coordinates of each position that the name will be located at, in the text area so then when a mouse button is clicked I will compare this position against a position of the name in the string output of array list that was passed from the server (i.e. [Adrian, Buddy, Bob]).
As I have mentioned before, I am using a scroll-able text area for showing the online list, therefore I am not entirely sure if this approach would work out once I scroll down the list and click one of the positions.
Perhaps you could recommend me another approach I could adapt, or clarify if this one would work.
Here is the image of my chat client:

As I have mentioned before, I am using a scroll-able text area for
showing the online list, therefore I am not entirely sure if this
approach would work out once I scroll down the list and click one of
the positions.
Working with Scrollable TextArea for selecting items and responding with it the way you described: it will just be a hazard. Use JList with ListSelectionListener instead.
Tutorial Resource:
How to use List
How to Write a List Selection Listener

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?

Swing (Java) Category List

everyone.
I'm currently working on a project which is written in Java. As one of my features I want the application to display List of workout plans that are saved in the databases. Furthermore, I want the user to be able to click on particular instance of the workout Plan so that new JFrame is opened with further details which will be populated from the database.
You can see what I mean in the picture below, this is how I want my list to look like.
For this application I'm using Swing components to model my GUI. Its very important for me that those items within a list will act as a button so that you can open up new JFrame, but at the same time the content must be populated from database. Also when a new Workout Plan is added to the database the list must be updated and the item that will be added to that list has to be of the same format.
My question is whether it's possible to design that kind of list using Swing components, and if it is how would you do it.
Any suggestions or help will be appreciated.
I'm not that familiar with swing but, I think you can set your panel into a grid layout. Then divide the grid layout so that there are, for example, 10 rows and 1 column. Afterwards, fill the grid layout with JButton's. Whenever a button is pressed, it will open up a JFrame.
I feel like there's a better way to do this though.

Java: Making a editable list of items in a JPanel/JFrame

Sorry, I'm kind of a beginner to GUI interfaces (well, a beginner to java, really), and I was wondering: How does one make a list of items that the user can add items to or remove items from, with the press of a + or - button?
What I really want (sorry if I'm being a little vague here) is one of those lists you sometimes see in application windows, which looks like a text box but cannot be typed in. Right now my application (it's a small app to organize the schedule of a hospital) just reads from a text file and writes to another text file. No GUI, no window, the user just writes a bunch of names in the text file, one per line, then runs the jar and opens the output file and the schedule is there. I want them to just be able to add or remove names from a list with buttons — adding a name by clicking 'plus' and typing the name, and removing a name by selecting the name and clicking 'minus'. I still, however, want it to save to a text file, so that the next time the user opens the app, all the names are still on the list.
Just to be clear, I don't want a list displaying the output (i.e. the names organized into a schedule), just one containing the input.
Thanks a lot for any help you can give.
You probably want a JList with a couple of JButton instances to add/remove items.
See:
How to Use Lists
How to Use Buttons, Check Boxes, and Radio Buttons

Creating a checkbox java list

i am trying to generate a checkbox list feeded by some records from a database just like the image (JAVA Swing), initially i tried with several chexkboxes but it didn't work, now i am trying with a multiple selection list but it didn't work as well and none of the answered questions here looks like to solve the specific needs i have.
Specifications:
Multiple selection list.
Every node of the list must have a checkbox object.
When checked every node must stay highlighted.
It must have an scrollbar if the content is bigger to the initially setted dimentions.
It must have an scrollbar if the content is bigger to the initially set dimensions.
Put the JList inside a JScrollPane.
When checked every node must stay highlighted.
This is going to confuse the user. The check marks are sufficient.
Every node of the list must have a check box object.
You'll have to extend a JList and a ListCellRenderer to gain this functionality. The ListSelectionListener that I have is over 100 lines of code.
You might find an already existing check box JList on the web. I have one in a book.

HTML gallery page in Swing with drag-drop functionality

I was asked to write a JDialog separated into left and right panel. The left panel shows a demo HTML template gallery (small sized), and right panel shows series or list of images. I want to make it such that I can drag image on the list and place it on the gallery (or maybe drag out some image from the gallery). The problem is I don't know where to start with this, can anybody give me some idea?
An HTML gallery typically uses JS to do the 'heavy lifting' (I'm guessing it will require a slideshow as well). While Swing components support HTML (to an extent) they do not support JS.
I recommend not trying to render the HTML/JS in the GUI, instead, provide a JList in the GUI of the image+name objects chosen by the user (using JFileChooser). When each image is selected, you can show the 'preferred name' in a JTextField that allows the user to edit it.
Image order can be shown by the order in the list. To change the order, implement Drag'n'Drop. See the Drag and Drop and Data Transfer lesson for more details.
You will probably need a JLabel in the CENTER of the GUI to display the (full size) selected image, and show the order & timing of the slideshow.
Once the user is happy with the image selections, the order, the names & timing. Offer them a button to write all the details to a single directory including the HTML, script & images (easier). Once the HTML is written, invoke Desktop.open(File) to display the finished product to the user.
As to how you do all that, it is really beyond the scope of an answer on SO. You would need to do the tutorial on each part, and come back with more specific questions.

Categories

Resources