Share on Google+Share on Google+

joel marroquim
search filter and JTable
3 Answer(s)      5 years ago
Posted in : Java Beginners

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

Ads

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
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
Advertisements
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
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
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
filter
filter  What is filter? Can filter be used as request or response
JTable
JTable  Values to be displayed in JTextfield when Clicked on JTable Cells
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  i want to delete record from JTable using a MenuItem DELETE. and values of JTable are fetched from database....please reply soon
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
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/Controller
Filter/Controller  what is the difference b/w org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter... one is filer. I have confusion with these two. Is there any d/f b/w filter
security filter
security filter  i have included WebFilter.java in my application. i am getting this error . error 500:filter[WebFilter]: filter unavailable. whats the reason for this error
JSF+Filter
JSF+Filter  What is the meaning of the tags: avoid-urls for filter configurations in web.xml.
search
search  how to develop search box and how to retrive data from database..   Please visit the following link: Search box
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
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
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
Search
Search   Hi, I have a project in which I am trying to enter "Marathi" (Indian local language) data in JSP using JSTL and trying to search data... and tries to search then It shows no data from database
esign filter for wifi router
esign filter for wifi router  How can i make a filter for my wifi router to filter packets from specific ip or mac address
filter implementation in java
filter implementation in java   How to implement filters in java?   Java - filter implementation Tutorials Filter Files in Java Response Filter Servlet Example
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
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads