How to put certain Data on Column in JTable? - java

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

Related

How update a jlist swing java

I had a problem. I am code a simple dictionary by using java swing
I want first to show all word and then whẹn i type a word or first of a word , it wI'll display this sublist . I try much but not successful, may someone help me
Instead of using a JList you could use a single column JTable. A JTable supports the ability to filter the rows of data in the table.
Read the section from the Swing tutorial on Sorting and Filtering for a working example to get you started.
You can even make the JTable look more like a JList by following these suggestions: How to create a JTable which appears as JList?

Using JTable to display ResultSet

I'm learning about JDBC with GUI. I can do that the GUI display the data in SQL one by one. Then i want to display the data in table just like the result when i execute in SQL. I saw that many people use two Vector to add data to JTable. I wonder is there anything else apart from Vector that I can do to add data to JTable.I really want to add some images in my post but i can't so sorry if it's uncovinient for everyone. Thanks for reading.
I wonder is there anything else apart from Vector that I can do to add data to JTable.
The DefaultTableModel uses Vectors because it makes the TableModel dynamic. That is you can easily add or remove rows/columns from the model.
If you don't want to use a Vector then you can create a custom TableModel to store the data any way that you want.
Check out Row Table Model. It gives an example
of how to create a custom TableModel using an ArrayList for the data
of to write a generic TableModel that is reusable

File to JTable, JTable to file

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.

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.

How to change data in JTable cells?

I can set data in JTable constructor, and then user can change this data when program is running manually(typing from keyboard).
But what method should I use in case I want to change data in some column? To change column header I use TableColumn method setHeaderValue. What should I use to set value in JTable cell?
If you want to allow users to edit the data, then you need to set a TableCellEditor on the cells that you want people to edit. You probably also want to start using a TableModel instead of hard coding the data in the JTable itself.
See http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
While creating the JTable you first need to specify that the values of particular column are editable. You can obviously also provide the row basis edit functionality. but all these things you should define while ccreating the table itself. Please reply if you need any help on this.

Categories