search filter and JTable

search filter and JTable

I first im not speak englis very well, so my question is:

how can i make search data in JTable of java?

i wan to search records in table or textfield but the data display in JTable.

Note: i dont have a table.

PLEASE HELP.... THANKS

View Answers

April 2, 2012 at 3:10 PM

import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.*;

class Search{
    public static void main(String[] args) {
        JLabel lab=new JLabel("Enter Name:");
        final JTextField t=new JTextField(20);
        JButton b = new JButton("Search");
        JPanel p = new JPanel(new GridLayout(2,2));
        p.add(lab);
        p.add(t);
        p.add(b);
        JFrame f = new JFrame();
        f.getContentPane().add(p);
        f.pack();
        f.setVisible(true);

        b.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
            String name=t.getText();
            try{
           Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from data where name='"+name+"'");
           String n="",add="",contact="",email="";

           if(rs.next()){
               n=rs.getString("name");
                add=rs.getString("address");
                contact=rs.getString("contactNo");
                email=rs.getString("email");
           }
           String data[][]=new String[1][4];
           data[0][0]=n;
           data[0][1]=add;
           data[0][2]=contact;
           data[0][3]=email;
           JFrame frame=new JFrame();
           String labels[]={"Name","Address","Contact No","Email"};
           JTable table=new JTable(data,labels);
           JScrollPane pane=new JScrollPane(table);

            frame.add(pane);
            frame.setVisible(true);
            frame.pack();

            }
            catch(Exception ex){
            System.out.println(e);
            }
            }
        });
    }
}

April 2, 2012 at 10:50 PM

thanks for you answer, now I can see by the code in my project ...


April 3, 2012 at 12:57 AM

Thanks I managed to enter the code in my project so give me this error when I call my button, for example in another package a class called desktopapplication i have an interface that runs on my table this in mysql, so I do not interface desktopapplication I have a button called search, but the button is called I put the code:

search demo = new search (); demo.actionPerformed (evt);

but he did not recognize that the action perfomed. because it will be???

tou asking for your help once again .................









Related Tutorials/Questions & Answers:
search filter and JTable
search filter and JTable  I first im not speak englis very well, so my question is: how can i make search data in JTable of java? i wan to search records in table or textfield but the data display in JTable. Note: i dont
jtable displays search results
jtable displays search results   hi sir can u send me full source code for displaying search results into jtable from database n jtable n search button must be within same frame but in different Panel and the size of the frame
Advertisements
Not able to filter rows of jtable with textfield in netbeans
Not able to filter rows of jtable with textfield in netbeans  ... of implementing row filter to the 4th column of jtable with a textfield but its...", "Item", "Qty In Boxes"}; tblStock = new JTable(data,header); sorter=new
Not able to filter rows of jtable with textfield in netbeans
Not able to filter rows of jtable with textfield in netbeans  ... of implementing row filter to the 4th column of jtable with a textfield but its...", "Item", "Qty In Boxes"}; tblStock = new JTable(data,header); sorter=new
Form with a search filter in spring mvc?
Form with a search filter in spring mvc?  Hi I am new to Spring MVC... into my jsp page, Now in the same jsp page at the right hand corner I have a search filter where I need to search by transaction id which is one of the field
Form with a search filter in spring mvc?
Form with a search filter in spring mvc?  Hi I am new to Spring MVC... into my jsp page, Now in the same jsp page at the right hand corner I have a search filter where I need to search by transaction id which is one of the field
ModuleNotFoundError: No module named 'django-search-filter-sort'
ModuleNotFoundError: No module named 'django-search-filter-sort'  Hi...: No module named 'django-search-filter-sort' How to remove the ModuleNotFoundError: No module named 'django-search-filter-sort' error? Thanks  
JTable
JTable  Values to be displayed in JTextfield when Clicked on JTable Cells
JTable
JTable  i want to delete record from JTable using a MenuItem DELETE. and values of JTable are fetched from database....please reply soon
JTable
JTable   how to select a definite cell which containing a similar text containg to the one which the user entering from a jtable at runtime in java
JTable
JTable  need to add values to a JTable having 4 coloumns ,2 of them are comboboxes
JTable
javax.swing.*; class Search{ public static void main(String[] args... JTextField(20); JButton b = new JButton("Search"); JPanel p = new..."}; JTable table=new JTable(data,labels); JScrollPane pane=new JScrollPane
JTable
JTable  Hello, i cannot display data from my table in the database to the cells of my JTable. please help me
jtable
jtable  how to get the values from database into jtable and also add a checkbox into it and then when selected the checkbox it should again insert into database the selected chewckbox.plzz help
jtable
jtable  hi Sir i am working netbeans IDE,I have a jtable when i insert values in jtable then i am unable to print all inserted values,For eg if i insert 1,2,3,4,5,6,7,8 values then , i am getting output
jtable
jtable  hey i have build a form and i m also able to add data from database to jtable along with checkbox.the only problem is that if i select multiple checkboxes the data doesnt get inserted into new database and if only one
JTable
JTable  Hi I have problems in setting values to a cell in Jtable which is in a jFrame which implements TableModelListener which has a abstract method tableChanged(TableModelEvent e) . I'll be loading values from data base when
filter
filter  What is filter? Can filter be used as request or response
How to show multiple identicle rows from database on clicking search button to jtable
in the jtable .Suppose i enter name in search field which has two rows in the database...How to show multiple identicle rows from database on clicking search button to jtable  Hello Sir, I made search button with textfield
How to show multiple identicle rows from database on clicking search button to jtable
in the jtable .Suppose i enter name in search field which has two rows in the database...How to show multiple identicle rows from database on clicking search button to jtable  Hello Sir, I made search button with textfield
How to show multiple identicle rows from database on clicking search button to jtable
in the jtable .Suppose i enter name in search field which has two rows in the database...How to show multiple identicle rows from database on clicking search button to jtable  Hello Sir, I made search button with textfield
JTABLE Issue
on Swing-AWT. I have used JTABLE to show data. There is "input field" and "search... frame which gets open on click of search button. this JTable also has a back button... for eg. Customer's name and click to search button data comes on JTable according
JTable - Java Beginners
JTable Search Filter  Hi,i wanted to add a search filter in my JTable application.Thanks in Advance!!  i'means using database access,when...=============================================================================i press the enter button into JTable cell and focus
JTable - Java Beginners
JTable search example  I've problem about JTable, i wan to search records when i types words in JTable cell,can u give the source code.I'm Beginner and i start begins learning java programming.Please send the example into my
JTable - JDBC
JTable   Hello..... I have Jtable with four rows and columns and i have also entered some records in MsSql database. i want to increase Jtable's... { JFrame f; JPanel p; JLabel l; JTextField tf; JButton btn; JTable tb
jtable problem
jtable problem  how to make a cell text hypertext
JTABLE OF JAVA
JTABLE OF JAVA  i have a jtable in java,i have used checkbox in jtable. now i want to add(submit) only those records that i have checked by checkbox how? i want small example with coding
Jtable-Java
Jtable-Java  Hi all,I have a Jtable And i need to clear the data in the table .I only Need to remove the data in the table.not the rows.Please help me
Swings JTable
Swings JTable  add values to JTable with four coloums,two of them are comboboxes
sum in JTable
sum in JTable  how to calculate sum from JTable's one field like total
jtable query
jtable query  I need a syntax...where i could fetch the whole data from the database once i click the cell in jtable...and that must be displayed in the nearby text field which i have set in the same frame
java jtable
java jtable  Hello Sir, I am developing a desktop application in which i have to display database records in jtable .now I want to read only... that in jtable. plz help me with the code
regarding jtable...
regarding jtable...  sir, im working with jtables. i wanted to populate a jtable from the database and when i click any row it should add a container... a container on the jtable. kindly help me sir. thanks in advance regards, rajahari
ABOUT Jtable
ABOUT Jtable  My Project is Exsice Management in java swing Desktop Application. I M Use Netbeans & Mysql . How can retrive Data in Jtable from Mysql Database in Net Beans
JTable duplicate values in row
JTable duplicate values in row  JTable duplicate values in row
How to add JTable in JPanel
How to add JTable in JPanel  How to add JTable in JPanel
jtable insert row swing
jtable insert row swing  How to insert and refresh row in JTable?   Inserting Rows in a JTable example
REPORT WITH JTABLE
(Exception e){} JTable table = new JTable(data, columnNames); JScrollPane scrollPane
jtable
JTable - Swing AWT
JTable row selection event   Hi, it will be great if someone can share an example of row selection event in JTable
JTable hold different components
JTable hold different components  create Jtable with two coloums,one coloumn is combobox and other normal
search
search  how to develop search box and how to retrive data from database..   Please visit the following link: Search box
JTable Pagination
JTable Pagination  Hello , I have the following Code. I am able to fetch the Data from the Database. But i need to implement pagination for the same. Can someone please help me out with this ? I have tried out many things from
JTable in java - Java Beginners
JTable in java  Sir , I have created an application with a JTable showing the records of an MS Access database table. On the same frame I have... given one , JTable table; ....... .... table.print(); Here the error
JTable - Java Beginners
JTable  can we merge two cells of one row in jtable
restrict jtable editing
restrict jtable editing  How to restrict jtable from editing or JTable disable editing?   public class MyTableModel extends...){ return false; } }   Disabling User Edits in a JTable Component
SEARCH
SEARCH  how can we do search in jsp...? option for search criteria like name and DOB...   Please visit the following links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/servlets/search.shtml
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable...); add(close); add(print); String[] search={"--search by--","Employee_ID","Employee Name"}; final JComboBox box=new JComboBox(search); box.setBounds
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable...); add(close); add(print); String[] search={"--search by--","Employee_ID","Employee Name"}; final JComboBox box=new JComboBox(search); box.setBounds
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable...); add(close); add(print); String[] search={"--search by--","Employee_ID","Employee Name"}; final JComboBox box=new JComboBox(search); box.setBounds

Ads