I'm developing a JAVA swing application, developed using hibernate and mysql as a database.
I'm trying to bind data from a JList to appear on a JTable, when one of items in the list is clicked. For example i have different user types in my application, Supervisor, Manager, Administrator and others.
Each of the user type has users register under them. I want the application to show certain users when a certain item is clicked on the JList. Like when I click on the supervisor item then all registered supervisors must appear on the JTable. Don't know if I'm making sense, but you all allowed to reply and I will try to make you understand better. Thanks.
Like when I click on the supervisor item then all registered supervisors must appear on the JTable.
One way is to populate the table with all the data and then filter the table when you select an item from the JList. Read the section from the Swing tutorial on Sorting and Filtering.
Otherwise you would need to dynamically query you database every time a JList item is selected.
In either case you will need to add a ListSelectionListener to your JList to invoke your processing. Read the section from the Swing tutorial on How to Use Lists for an example.
Related
I'm trying to hide (not remove) some items from a JList Java, but I can't find the way.
The process I'm trying to realize is a list with JCheckbox and a search form (textfield). When the user fire some text I filter the list, but I need to keep the state of the checkbox, so I can't remove the item, but only hide or show it.
Thanks for the help.
When the user fire some text I filter the list,
JList does not support filtering.
You can use a single column JTable. JTable does support filtering.
Read the section from the Swing tutorial on Sorting and Filtering for more information and working examples.
I'm in a position, where I have to populate a JComboBox with names from my users (5 users). When the user clicks the name in the JComboBox I want to retrieve the UserID of the user, not their actual name due some of them may be the same, and make a SQL query with their UserID as WHERE filter.
I have the all the users informations temporary stored in an Object, retrieved by a MySQL database.
How can I code a way to put more informations in the JComboBox, but only show the actual name to the user?
I hope this make sense, elsewhere feel free to ask questions.
Thanks in advance,
Jesper.
Create a User object that contains the name and user id with appropriate getters (and setters if required). Add these to the combo box. Use a ListCellRenderer to define how the User object is actually renderer.
See How to use comboboxes for more details
Check out Combo Box With Custom Renderer. It explains that you need to follow two steps to implement a proper solution:
use a custom renderer
use a custom KeySelectionManager so you don't break default combo box functionality when using a custom renderer
I have developed an Eclipse plugin, when I clicked the button a table appears on the view. However, this table does not refresh itself, when I click it again or when I a run operations on the table (such as deletion).
While I was implementing my table, I used TableColumn to create my columns and "TableItem" for the rows and values. Therefore, the "TableViewer"s refresh or remove functions does not work.
My table is able to appear, when I click the button and I call this function in the handler, such as;
HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView("ViewID");
However, still I am not able refresh it. Any help would be nice.
Thanks!
Basically, you need to call viewer.update() whenever you want to refresh or update the table. SWT tables and JFace viewers does not have a way to monitor the data model.
Alternatively, you can use Eclipse Data Binding to bind the model and the controls/viewers together. Have a look at this entry level tutorial to get you started.
I am using JXTable to display a list of records.
When I click "Refresh" button, I want the JXTable to be refreshed to display the newly inserted records.
And also when I click "Add new Row" button, a new row must be added to JXTable.
How can I do these? I am unable to find any useful reference or samples. Please guide me.
It works the same as with a regular JTable, which is all explained in the table tutorial. But to answer your questions:
There is no need for a 'Refresh' button, unless the 'Refresh' button updates the TableModel. The moment you update your TableModel you should fire the appropriate events so that the JTable is aware of the changes made to the model. At that moment, the JTable will refresh itself automatically. If your TableModel extends from DefaultTableModel there are already methods available which take care of the events (like e.g. insertRow)
Inserting a row means adding a row to the TableModel + firing the appropriate events. If you use a DefaultTableModel, you can use the available API of the DefaultTableModel
I am doing a small project for restaurant billing.In the billing form when the user enters the item ,i need the list of possible items to be displayed from which the user can select the appropriate item and all the details of the selected item should be filled in the table. ( just like a super market billing). The items are stored in the database (MySQL) and i am using java swing for user interface
Can anyone please suggest some way for achieving my requirement.Some helpful links as well. ThankYou..
You can use auto-complete package
You can use Swingx.Contains extensions to the Swing GUI toolkit, including new and enhanced components that provide functionality commonly required by rich client applications. Highlights include:
Sorting, filtering, highlighting for tables, trees, and lists
Find/search
Auto-completion
Login/authentication framework
TreeTable component
Collapsible panel component
Date picker component
Tip-of-the-Day component