Hello i have this Abstract Table which im making a video hiring application with. I want the user to be able to sort through the table with buttons I have supplied. In the buttons I have a "Show only overDue videos" so when the user hits this button in my action listener i want to be able to hide the rows not delete them so when the user clicks another button they will re-appear any ideas on how i would go about doing this?
Use the filtering support provided by JTable.
Read the section from the Swing tutorial on Sorting and Filtering for more information and examples.
1) Maintain a master Data list. Intially the table model data will reflect the Master data.
2) When the user "press show only over due vidoes", iterate the master data and filter only the required elements and clear the table model and add only the filtered data to the table model and fire table model changed.
Related
I have some data in a jTable and want to query a category (Chairs, Desks, etc.) with a drop down box and a search button. I want to have the user select a category, such as Desks, and click the jButton Available Furniture, and be shown a message like: "There are 5 desks. They are Small Office Desk, Large Office Desk, etc." How can I do this?
Here is a picture of the program with the data so you can see what I mean:
jTable with some information and furniture categories
Maybe the easiest way to do this is to just "filter" the table when you do your search by the keyword.
Read the section from the Swing tutorial on Sorting and Filtering for a working example.
You will just need to modify the code to get the search keyword from a combo box instead of a text field.
I connected MySql database with Java app, I see data from two different columns (Items, Price) but I want to connect them somehow, for example, if choose in first combobox item "Desk" the other combobox should automatic find "Desk" price and display it in second combobox. Anyone have idea how to make that ?
You could write a changelistener for the first box, then have it go into another sql query which will populate the second box. Check out this guide, it'll explain to you how to do it
https://docs.oracle.com/javase/tutorial/uiswing/events/changelistener.html
First, I think that you don't want to ComboBoxes being correlated in such a way. There must be a better design for your gui.
Is your ComboBox from JFace? There are JFace Data Bindings. Normally, you use them to automatically update your model if someone changes values in the user interface. If your model contains an id from your database, both comboboxes can have a binding to this id.
I am facing a problem with JTable when inserting JTable values into the database. For example I have three columns, and user enters the corresponding data into three columns, JTable has several rows and I have one submit button at bottom of the table. After filling the data into all the rows, when the user press the submit button, the data is inserted into the database. This works fine without any problems.
Now consider user enters only 10 rows and he didn't click the submit button, because of some power failure the system shutdown suddenly. Now I want to store these 10 rows in a collection and when the application is started again I want to insert these 10 rows values automatically into the database. Please consider that user information is very critical information. I don't know how to do this.
Rightly said by #madprogrammer you have to take help of temp tables,
just add a action listener to ***jtable***after insertion of row data it will transfer your data into temp tables.
-- after click on submit button, there should be check that if data is present in temp tables, first insert these data into main table.and truncate or delete data from temp tables.
here collection will not work for you.
Hope it may help you.
I want to put subject results in a Jtable. I set DefaultTableModel to the table. In my table I have three columns.Student ID,Marks and Grade.Student ID is auto generated in column one.then user should enter marks for for second column.Then I want to automatically put the necessary grading in 3rd column.I load the grading data from the database and find the correct grading for the marks.I try this with both MouseReleaseEvent and KeyReleaseEvent.But it wasn't successful.Can any one suggest me a better way.thank you.
You don't have to listen for the input events, because the table has cell editors already. So you should be capable of editing your table. The only thing you need to do is to listen for the tableChanged event and update the database there.
See: TableModelListener
In case I was confused by your thoughts about the events and you just want to basically set values of a cell programmatically, try this method: setValueAt(Object,int,int)
Creating front-end (Java) user interactive table using MySQL as back-end
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.
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!
i need code for creating table ...
ple help me on tis....
i need code for creating table
How much will you pay? :)
..i need the corresponding TextFields to display the corresponding row user selects in the displayed table..
For that you can use,
Give a button, like EDIT and in the event handler for EDIT use something like,
jTextField.setText( jTable.getValueAt(
jTable.getSelectedRow(),
jTable.getSelectedColumn())
.toString()
);
2.As an alternative you can also utilize the event in jtable like mouseClicked with the above code
Now regarding the edit and delete , you may utilize the focusLost event of the textfield or use a EDIT or DELETE button, and carryout the updation, which will be much reasonable option.
Additionaly have a look at this : Using JDBC with GUI API