File to JTable, JTable to file - java

I have been working on JTable,
My project:
read data from database (I finished this task and able to display in JTable).
then display and save data into subgroups into file (text/excel).
I have basic knowledge on JTable and using the some example code, I could manage to finish my first task. Then struck on second task.
for example
name| email|
name1|email#email.com
name2|email2#email.com
(I finished this task and able to display in JTable)
Then
when user clicks any row
then displayed new table
name|Email
display----
then user should able to save the group with groupname
Can anyone has idea about how to update the table dynamically and any suggestions?

Can anyone has idea about how to update the table dynamically and any
suggestions?
If you are using DefaultTableModel then you have methods like addRow(..) which will append a row in the JTable. Updating the existing rows in JTable is done using setValueAt(..) method. No need to call fireXXXMethod for DefaultTableModel.
Or
If your are using AbstractTableModel then use the setValueAt(..) method and call fireXXXMethod in the table model to refresh the table data.

Related

How to put certain Data on Column in JTable?

Im Very New in java and im still learning how to put data on notepad. but i want to put one text to the JTable. I Dont know how to put those arrowed text into JTable
You should make a TableModel then add rows of data to your table model. There is plenty of information here https://docs.oracle.com/javase/tutorial/uiswing/components/table.html

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.

adding pagination to all tables using jtable in jsp

I have done pagination to a simple table using jtable in jsp.But it only works to that table.I have write a code which will give drop down of all tables present in mysql database.Now how to write pagination code in the way that if i select a table it should display all the data in that table using pagination and CRUD operations from User Interface .I have done it for only one table .Now please give an idea how to make these tables to display the dynamically selected table with pagination.
You will need to generate the jtable configuration on the selection of your table in the dropdown.
Create the jtable configuration for all your table then change (destroy the jtable using $('div1').jtable('destroy') initialize your div with selected table configuration.
Here is the answer for this requirement (stackoverflow.com/questions/27644483/dynamic-fields-using-jquery-in-jtable)

Auto update JTable after INSERT statement

I am using Derby and Eclipse/Java. I have a table in a database which populates a JTable in a scrollable frame. I enter data for a new row in textedit fields and commit to the database with an INSERT sql statement. I want the displayed table to automatically update and have googled extgensively to find out how to do this. I understand that fireTableRowsInserted should trigger this. I have a tableModel class extending AbstractTableModel. If I call fireTableRowsInserted from my entry class the table doesnt update. From searching I thought that the table listens for this event - do I have to create the listener, if so I havent been able to find a clear(to me!) indication of how this is done and would appreciate a pointer to a source that would help.
Is there a good book or online reference on using databses,sql and a Visual Designer with Java?

Steps to read the text file into specific columns of JTable using biojava

Here is a typical input .txt file (also called as fasta file):
>contig00001 length=586 numreads=4
CGGGAAATTATCcGCGCCTTCACCGCCGCCGGTTCCACCGACGAACGGATACTGCGtGaa
ggCCGCGATCCCGTCggaCGGAAAaCGCCcTGGCCCGGGAaCATACCGTTCGGGCCGCCA
AGTGTTATAGCCGGACCACTTGTCAGAACATTTCCaaTCCGAAGATGTGAGTtCGGAAGg
TAAAAGCCCGACAAGTTGCGCGgTGAATTTACCTTtACcGCACGATATGCGTCCGTATTA
AaGAAAaGTTCGAAATTATCAGTAAGGCCGACCTGAAaGCTGACCGGGAGTTCAACAAAA
TCTGCATCACCcGGgTCACGGTCGAAATTGCTGTACGCGGCGCTGAACGTAAATTCACCC
TTTcTAAGGGTGTCGCcGTCGTAAACCGTAAaCAaGCCGGTAGCGCCGCCCATCGGGCCG
CCGGTACCAACCGTCGGTGCCGTGTTTCTtGCATCATTGTCCGATCGAGCGTTCTCGTCC
GCTTGTGCAAaTCCTGCAaTAGCTAACGTGAAAACGATCAGAGCTGTTGTAAATACTCTA
TAAGCGAGATTCATCACATTCCTCcGCCGAAATAAAAAGTTAATTt
>contig00002 length=554 numreads=4
TGCGCCAaCCGCGCTCTtCATAAaTGGGCACTGCTCCCGATGGCCgACTCGGGCGGTTCG
CCATGAGATCTTTGCCtACCcAGgAaCtCACcACCAAGTCTGATTGCTGTGTGTTTtCTT
CAAGTCCCTATTTCTATTCtCTTtAATGGAACCCGTAGGAAACCCGTGTAGGACGCGGGA
aCCGCACTTgAAGGGGGAGGCGCGGGGTACCGGtCCGGGAACGTACGGGTACCGGCGGGG
gAGGGGAGGGGGACCgCTCCGGGAAGGCCAGGGGACGGATTGGGGAAGGgCGGGTACCGA
AGCGGGgAAaTGGGggAaCcGGCGAGAGGGTTCCTCGCTAAGTGGGGGAAATaGGGGAAA
GGTTGACCAGTGGTtCCCcGCTCTCGTAACATGCCTCAGATAGCGCCATCCGCTGTACCT
GGtcaggtcGctggcaacttcggccgagcaggtgaacccgaaaggtgagggtcagtgtga
cacaccaaccgaacaccgacgaggcaagcgtaggagccggcgtggccgcgcccggcggcg
ctgaggactcctcg
Code to read the sequence may be found here.
It gives the proper output, as shown below with tab seperation:
contig00001 586 52.38
contig00002 554 62.45
The problem is that I developed a form in NetBeans that consists of a JTable having 5 columns i.e:
"contigID","Description","Organism","Sequence_length","Gc_percentage"
and a JTextArea. I want to display the above output in the JTable columns, while the other columns remain empty; and when I click 'contig00001' in JTable, then respective sequence like "CGGGAAAT...." should be displayed in the JTextArea.
How can I do that? Any suggestion would be appreciated.
I'm not exactly sure what you're stuck on. If it's adding data to the JTable, I'd consider creating a DefaultTableModel object, constructing it with the correct column header Strings in an array, with 0 rows of data, and then adding rows of data as you read through your files. The JTable tutorial should help you do all of this. Once you have your table model created, you can add it to your JTable easily via its setModel method.
One approach is to extend AbstractTableModel, as discussed in Creating a Table Model.
Addendum: By listening for a user selection, you can determine which row was selected and update your JTextArea accordingly.
Addendum: Because data retrieval may be prtotracted, SwingWorker offers a safe way to mutate the TableModel. Here's a simple example.

Categories