How to edit and search data (words) in jTable? - java

I am beginner in Java, only know basic stuff.
I would like to know how to edit and search data inserted to jTable? So like I type some data in textbox and added to jTable and then type in a search text box to find a specific word in jTable so it'll show up in jLabel.
Then for editing, i don't even know how to do it. No idea. Plus, this all should be in a separate java class, not in .form (design) part in GUI. A sample GUI Java application would be very much appreciated.

Read the section from the Swing tutorial on How to Use Table for the basics of using tables. There are sections on:
Concepts: Editor and Renderers
Sorting and Filtering. You might want to use filtering to search for a string.

Related

How to implement codes in GUI formed apps in Java swing?

I really have a hard time finding help on internet since no one is giving examples on how to implement codes in GUI formed app. So I have my interface created and whole app works through buttons. Every code I find is for just workspace line, or how would I call it. Now I want do the following:
I have an input page for registering members in the gym. When I register them, they go to jTable. Now, I want to make it possible to edit columns Weight and Instructor from the table. I saw how to add ComboBox into table column, but don't know how do it in GUI formed app, where table is not created by the code. And I want to edit Weight column with jTextField the same I would do with ComboBox for instructors.
The question can also be: How do I define these custom things in table (or any other object in GUI Java App) when I already have GUI table set on place with drag and drop in NetBeans?

Select from a UI list and perform an action

we're building a small chat app for an assignement in our university. I have a question regarding how I can implement something.
This is our ui. The big white part is a jTabbedPane where conversations the user is participating in will appear. The two small ones are where active groups and active users will appear.
I found out that I can populate a jcombobox from a linkedlist using .toArray. I don't know what ui element to use, in order to display the list elements one under the other, and being "selectable" (only one at a time). The concept is that the user will select a group and press "Join", to, well, join.
This is what I have in my as to how it will look in the end.
Any pointers and advice in general would be greatly appreciated.
It looks like you're wanting to use either a JTable or a JList -- one with a custom renderer, a renderer that displays both the group name and its "status"(?).
If a JTable, then your key job is to create a TableModel that will accept your data well, either by using the DefaultTableModel (the easiest way to do this), or by creating your own model derived from the AbstractTableModel (a little more difficult, but more flexible).
For a more detailed answer, consider providing pertinent code, preferably as a minimal example program or MCVE.

Swing applications that prints the MySql Database records

I need some help with choosing the right swing component to print the records from database, to be honest I was thinking its going to be easy with
http://mysql.aldenwebhosting.com/JAVAtutorial/uiswing/components/table.html
BUT it doesnt cache, its just prints raw code into tabel. Can someone help me?
In its final stage, my app would download records after I press the button, then print them into some form of label, tabel,field whatever (bassicaly I dont know which swing component choose) . Next step is going to be editing one of the column parameter (binary-like yes/no) and saving it to database - I don know if thats important - im writing it just in case, so you can see the whole "picture"
Greetings!
To build an editable table in swing, I would suggest you to use a JTable with a custom table model and choose a JTextField component for your cells.
If you are not using any JPA frameworks like Hibernate, IBatis.., etc. I would recommend to use one because it helps lot in dynamic persistence in this case.

how can i programatically select a particular text from JTable when i do search in it?

here are the screenshots of the application
Rows will be displayed in the Table according to the text which is written in the search textfield.
Now i want to mark that particular text as per the shown in the second image with the yellow color
I know how to select a row or a particular cell.
but I don't know how to select a particular text inside the cell of any row in the table.
I am guessing you know how to search in JTable, so I am not pasting code of it here.
You can look over the SwingX library. It has this kind of function as you said predefined it it. You just need to add it to your table. This is where you can find it. Give it a try you will surely like it.
The basic premise would be to use a custom TableCellRenderer that provided the functionality that you require.
The problem is how to implement it.
I would create a TableCellRenderer based on a JTextField, remove it's border and make it transparent. This will allow you to use the text highlighting functionality provided by JTextCompoent to highlight portions of the text, as demonstrated here.
The next problem is then knowing what to highlight. There are a number of possibilities.
You could provide a method in your table model that could return the current text that should be highlighted.
I'd, personally, probably use the JTable#putClientProperty and JTable#getClientProperty methods to seed the search text.
Or, you could actually provide a simple model that directly to the renderer which had a method that returned the current search text. This might actually be more useful as you could link it to field, the method building the filter and the renderers and allow them to simply seed each other

How can I copy a table from Derby DataBase into Swing application applet?

Is there any way of loading complete table from DB into a Swing Cardlayout's Jpanel?
My try was by creating a label for each line, but then things looked very faulty as if I had a column that had more text it was shifting the next column text and whole thing is messy.
Any ideas?
Note: I found that there is something called Jtable, and it might help, but I do not know if I can do that my table cells will be transparent and will reflect a background image?
A JTable will definitely help, but there's a bit of a learning curve. You'll want to learn how to create and populate a TableModel, and then pass that model to an instance of JTable.
If you're trying to build a simple database browsing tool, you might try using SQL Squirrel: http://www.squirrelsql.org

Categories

Resources