How update a jlist swing java - 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?

Related

How can I add a List to the JLabel?

I'm writing Java game right now, I have a problem that I have a List which type is Ranking, with the fields name and score, and I would like to add that fields to the JLabel. Method setText() unfortunately doesn't fix. What should I do?
with the fields name and score
A JLabel is not designed to display multiple lines of text.
You can format the text using HTML.
Or I would suggest a better approach is to use a JTable, which is designed to display data in a row/column format.
Read the section from the Swing tutorial on How to Use Tables for more information and working examples.
I have a List which type is Ranking
You may also want to check out Row Table Model for an example of a custom TableModel show how you can display your Ranking object in a table.

How to make filterable to jtable record using netbeans ide

There are many rows on above showing jtable. I want to filter record by short code. If I type short code like 1234 it should be display only short code 1234 associated row on jtable.
Thanks
You're going to have write the code...Start by checking out how to use tables, in particular sorting and filtering
The basic requirement would be to attach an ActionListener to both the field and button (you can do this from the form editor if you wish).
Within the actionPerformed event handler method, you need to create a RowFilter and apply it to the tables RowSorter.
A table can be configured to automatically create a row sorter by setting the autoCreateRowSorter property to true.
It's all explained nicely in the linked tutorials...
And another example

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 add columns/rows to an existing empty JTable?

I am developing a software for which I need a basic Java Swing UI. I am using Netbeans which enables me to drag and drop UI component. However there is a final result table that I need to display using code.
In my UI using trhe IDE I created a JTabbedPane, inside which I added an empty JTable (no rows nor columns) called finalOutputTable. Now I want at runtime to fill this table, let's say with columns: x, y and rows: row1, row2 & row3.
How can I do that by coding?
You need to make a custom TableModel that will allow you to support this functionality. JTable is just there to display the table on the GUI. The TableModel has all the business logic of what the data is and how each cell should act. To do this you will have to step away from the GUI-Builder and write actual code.
Tutorial: Creating a Table Model
inside which i added an empty JTable (no rows nor columns) called "finalOutputTable".
You need to add the data to the TableModel. Then you use:
table.setModel(...);
to display the data. You may also need to revalidate() the panel containing the table if you didn't reserve space for the table when you created the form.
How can i do that by coding?
See the Laying Out Components Within a Container lesson of the Java Tutorial.
You can also use a TableModel witch does all that hard work for you.
https://github.com/MarkyVasconcelos/Towel/wiki/ObjectTableModel

Java Swing: what class can be used to implement this?

What Swing class can I use to implement something like this?
Add To List http://img22.imageshack.us/img22/3260/swingwidget.jpg
EDIT: Hmm..for some reason I cannot add the image here. Well, here's the link:
Basically, I need a list table, where each column can be of different type of gui (i.e. plain text, check box, or drop-down menu).
EDIT I have re-publish the image for you ;)
You would use a JTable to implement it. Your data will be stored in a TableModel. The DefaultTableCellRenderer and DefaultTableCellEditor should do what you need, but you can also customize the rendering/behavior if necessary.
More info on renderers/editors: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editrender
Definitely JTable.
JTable allow you to define what render will have each column. That way you can add checkboxes, combos, textfields etc. to it.
Here's an screenshot:
alt text http://img43.imageshack.us/img43/9430/jtable.png
You can read more about it here: How to use Tables
JTable will do this for you, you're going to need to understand the MVC pattern pretty well to acheive this as you will need a custom model and renderer, but once you get the hang of it its not too hard.
David gearys book "Graphic Java Vol.2" has an excellent section on JTable, whilst this book is now fairly old I still personally think thats the best explanation of JTable I've seen.

Categories