Creating front-end (Java) user interactive table using MySQL as back-end - java

I'm a student, intrested in Java programming. Now im trying to create user interactive form.
Untill now, I have created a form view, using swing components, JLable, JTextfield where user enters data. JButtons, 'new' 'save' 'delete' 'edit', which listens user action through ActionListner.
A table that 'extends' AbstractTableModel. Table values are the ResultSet values. i have used MySQL connectivity.
Table is displayed. User can now add new row to it, using 'New' and 'Save' button.
Please watch this
My problem is, i need the corresponding TextFields to display the corresponding row user selects in the displayed table, so that 'edit' and 'delete' would be user interactive. users are allowed to select table's row.
Need Help.
Im sorry if any mistake in my question format and language. Thank you!

on row select event, populate the values of text fields with tables selected row values.

As discussed in How to Use Tables, JTable will supply a default editor for any cell in your TableModel that returns true from isCellEditable(). Just double click on the cell. See also User Selections for more on selection listeners.

Related

Select all Same jtable value in one click

I am creating a prototype of a payroll for my project, i would like to ask, How can i select all value with the same name and Employee's id in table with just clicking one of them? And all the selected row will pass to another table. Please help me, I just don't have no idea on how to do it?
How can i select all value with the same name and Employee's id
First of all I would suggest that it is the Employee's Id that is unique, so you would want to search the table for the selected id.
Easiest approach would be to "filter" the table based on the Employee's Id. Read the section from the Swing tutorial on Sorting and Filtering. The working example shows how to do a dynamic search as you type text into a text field.
And all the selected row will pass to another table
Now you have all the filtered data in the table to you just iterate through the JTable using the getValueAt(...) method to get the data you want and that add the data to another JTable using the addRow(...) method of the DefaultTableModel of that table.

SQL two different tables in combobox and textfield from same database in Netbeans

I have created a MySQL database in Netbeans with two tables (varchar and integer), both connected on the same database, and three GUI elements jcombobox, jtextfield, jbutton and jlist. How is it possible, when connecting varchar table to jcombobox, to make jtextfield to remember numerical that is relative to varchar table?
(for example, varchar that is displayed in combobox has columns like
computer,laptop, console and integer has columns 500 (computer),
450(laptop) and 250(console))
and so user can put numerical values in jtextfiled
(500 , 450 and 250 are not displayed but remembered when user selects
one item from combobox)
and after user clicks on button, the value that user has put in jtextfield are being multiplied to numbers in integer table
(whatever user chooses in jcombobox)
and then final result is shown in jlist (or is jtable is better for such data representation?) where is shown choosen item, lets say it was laptop with calculated numbers, for example 4050.
Is it possible, and how, to make those tables to be assigned to different GUI elements and then get together again?
Thank you, and sorry for confusing English.
(500 , 450 and 250 are not displayed but remembered when user selects one item from combobox)
Then you need to store an Object in the combo box that contains two properties:
the description
the number
Then you render the combo box to display the description, but then for later processing you can access the number for calculations.
For an example of this approach check out Combo Box With Hidden Data.
and so user can put numerical values in jtextfiled
Maybe you should use a JSpinner so you get automatic editing to make sure only numeric values are entered.
You can use onFocus event on the jCombobox which then pass the value as a SQL query and fetch the corresponding details and then show that in jTable.If you have larger number of values then I will say use Jtable as for better representation.
Moreover, please add some more details to your question.

Moving the row selected from one jtable to another (Java Eclipse)

I am trying to create a feature in my program where the user can click on one row from the Jtable to select it (Jtable is populated by data from the mysql table). Then, the row will be copied to another mysql table that is identical in terms of names of the columns. What is the simplest way to do this? I am somewhat familiar with SQL queries but I am not sure how to implement the part where the user clicks on the row in the jtable.

bind data from jlist to appear on a jtable

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.

Select table values to text field using SWT?

I have Table (TableViewer) containing TableItems with values. I have another class TextField mapped according to table column name.
Now my question is: When I select any row in table, the values in that row should get reflected in Text field. In Text field I can edit these vales and save to to table. Please let me know how I can achieve this?
What ever "Baz" has said is the right thing to do. If editing is table data is requirement, then make the table columns as editable. But if you want to specifically edit table row separately in a control (like Text field), then get IStructuredSelection from TableViewer and get the data in control to edit. Then after you edit, get the data back from control and set it back to table. Hope it helps.

Categories