Dynamic amount of entries in GUI using java - java

I'm working on creating a basic user interface and I wanted to try and create a portion that is in a scrollTaskPane and is capable of holding multiple entries. As I'm going about creating it I can obviously test it with a simple amount of entries but I'm confused how I can go about later allowing for it to take input to create entries in the scrollTaskPane of maybe 1 entry one time, and then later needing to allow for input of 20 entries. I only know how to use absolute positioning and am trying to figure out the best way to go about it. I also need to later be able to select each entry.
For the entries that will eventually be called and displayed in my interface, I'm planning to store them in a simple text file and use a semicolon as a delimiter between the task "Type" "Name" "Description"(which will be accessible through a button) and "Due Date". Or I may try to learn to use a database for the information. But I haven't decided yet and don't know anything about connecting a database with a java program.
This is the current look (the scrollTaskPane in the middle). And my goal is to put in entries that are each rectangle boxes going across the scrollTaskPane with a checkbox on the end of them. Should I use some sort of grid layout? Or something else? I'm a beginner at user interfaces, so any help is appreciated!

You can make a custom layout, and then keep adding those layout. So extend a layout class, add TextField and a check box in the layout. Initialize the layout with your values, add then add to the ScrollTaskPane.

Related

How to iterate over elements of the same type in Android?

I have been working on a (probably bad, but I don't know enough about Android Studio) application for displaying objects from lists that may be on multiple lists (Magic cards that are in multiple decks), and because I'm bad I have a 21 checkbox view to represent each deck. When these are checked, it allows me to sort and filter and what have you, but I cannot figure out how to iterate over all of them without manually writing up a hard-coded array of their IDs.
Each of the checkboxes was created manually. If there is a better way to do this, feel free to answer with that as well/instead.
EDIT: I don't have any example code (aside from knowing that findViewById(R.id.checkBox1) returns the first checkbox), but here is a picture of my current layout. I am using a blank project with no special layouts or anything. All of the checkboxes are independent and the only thing they have in common is that they are on the same page.

Best way to implement a selection box from a large number of entries

I have a large set of data from which the user has to select one. I'm thinking of a way to implement it (of course, in a GUI). I have a few ideas. But just thought of posting here as there may be better alternatives..
Say, user has to select a name from a large set of user base. If I simply put a text field for user to enter the name, then there can be issues like entering same name in different formats, misspelling etc...
I see two options here
Using a combo box
Using a list (Actually i'm thinking of something like a tool tip. As I cant show the whole list always due to space issues)
But combo box won't be much user friendly i guess. As the user will have to scroll around the whole list to select an entry. If the number of entries are too large, this will be
Which means, now I'm left only one option. A popping up list, which will change the content according the text user is entering in the text field. So he can type first few letters and the list will show all the entries starting from the entered text. Got my point, right?
Are there any other better to achieve this kind of need?
If I'm going to implement above, what will be the best way to follow. I'm thinking of extending the JTextField to add required functionality. Well, I'll put some method to set the popup list entries. And I'll add some actionListner to watch the text field, and control the popup list accordingly...
Autocomplete is what you are probably looking for. Google for "java swing jcombobox autocomplete" and limit results for the last couple of years to get relevant results. There will be a lot of examples and ideas on how to implement this with custom code.
I believe there is also some custom libraries like "swingx" that provide at least partial or full implementations to save time.
http://swingx.java.net/
They have released code as recently as the beginning of this years so it appears active and might have what you need.
You could take a look at SwingLab's autocomplete feature, it allows you to attach it to a JCombBox, JList or JTextComponent
use AutoComplete JComboBox/JTextField
based on Standard Java Classes
no issue with larger sets of data
no issue with Focus, BackSpace Key, Caret
for better performance to required sort the array before use
simple workaround for setStrict(true/false), restrict input to array

Custom component for JList instead of just strings

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).

Cloning a frame/tab with swing components/buttons inside

OK a complete revision:
I have a JFrame with a tab that has buttons/textfields etc. inside.Buttons have events that does simple things like reading from an SQL server and filling the textfields from the received query.Pretty simple eh? And now ,I need to add more tabs to this Frame and have to have multiple tabs.In each tab I "must" have the same components/events. So what I am asking is this,how can I clone all the components/events/keylisteners etc. (whatever i have inside that tab) to another tab? I could always add the same components with different names from the code,but I need to find a way to clone the whole tab..
Why not keep the components you already have without duplicating them, and figure out a way to store all the data to be displayed in some kind of model. You could create only some buttons to simulate the tabs, and when clicking on one you display the data associated with it.

Help with Java program (Swing + database)

Could somebody give me a suggestion on how to simply and effectively make GUI representation of directories which are contained inside the database. Now, getting information using SQL queries is one thing. I can do that.
In fact using separate small examples I can put a file inside the database along with his information and I can get the file out of the database. The thing is I was just doing this without GUI, just to test does it work.
Now I need a GUI of this and I really don't know where to start. DO I use JTable, JList or something third? Also, I think I need an multidimensional array because I have, for example, id of a file, name_of_file and size.
So I need different types to put them in: int, String and int.
Also, I need to obviously hide the id of a file from the user yet keep it at the same time in order to be able to reference it.
How do I hide it in a GUI component?
So, let's say that I have a database table for files with these columns:
id, name, size, binary_of_file.
My real table has a bit more of columns like, id of a parent directory, id of a owner, etc. but for now this is not important.
So, I tell database to give me all info about the file (except it's binary because I just want to list the files):
...
ResultSet rs = statementObject.executeQuery("SELECT id, name, size FROM Files;");
while(rs.next()){
//Where do I store the values in? Which GUI component and how?
...
I guess I need an JPanel that will contain this component that will show my files from the database. What component? Please help!
It sounds like you want to use a JTable, it has a TableModel interface that you can implement to adapt to your resultset.
Also follow the link at the top of the docs. to Creating a Table Model.
Perhaps a combined JList/JTable component would fit this need.
That is a screen shot of the GUI of FileBro.
My idea is that the JTree on the left would represent the 'directories' and table (names) of the DB. The JTable on the right would contain the data of the selected table. Change the Locate Open Edit Print buttons for Create Update Delete and the panel below that to show details of records, and it would be the start of a DB CRUD component.

Categories