how to show search results in the same panel of jframe to where search field and button is present..

Ads
 

how to show search results in the same panel of jframe to where search field and button is present..

Hello Sir,

Sir i do have one more query ,In the given code search results is being displayed in the other jframe.

But in my application i need to show search results in the same panel of jframe to where search field and button is present .

please Sir, send me the code for that. will always be gratefull. Thanking you nd waiting for reply ........

View Answers

July 12, 2012 at 11:39 AM

Here is a code that search the data from the database and show multiple identical rows from database on clicking search button to jtable.

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

class Search{
    public static void main(String[] args) {
        final Vector columnNames = new Vector();
        final Vector data = new Vector();

        JLabel lab=new JLabel("Enter Name:");
        final JTextField t=new JTextField(20);
        JButton b = new JButton("Search");
        final JTable table=new JTable();
        final JScrollPane pane=new JScrollPane(table);

        JFrame f = new JFrame();
        f.setLayout(null);
        lab.setBounds(10,10,100,20);
        t.setBounds(120,10,100,20);
        b.setBounds(120,40,80,20);
        pane.setBounds(10,70,480,170);
        pane.setVisible(false);
        f.add(lab);
        f.add(t);
        f.add(b);
        f.add(pane);
        pane.setVisible(false);
        f.setSize(500,300);
        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+"'");
           ResultSetMetaData md = rs.getMetaData();
            int columns = md.getColumnCount();
            for (int i = 1; i <= columns; i++){
            columnNames.addElement(md.getColumnName(i) );
            }
            while(rs.next()){
            Vector row = new Vector(columns);
            for (int i = 1; i <= columns; i++){
            row.addElement( rs.getObject(i) );
            }
            data.addElement(row);
           }
           DefaultTableModel model=new DefaultTableModel(data, columnNames);
           table.setModel(model);
           pane.setVisible(true);
            }
            catch(Exception ex){
            System.out.println(e);
            }
          }
        });
    }
}

July 12, 2012 at 12:46 PM

Thank you deepak Thank you very much .Excellent job .

once again thanx ...........

Ads









Related Tutorials/Questions & Answers:
how to show search results in the same panel of jframe to where search field and button is present..
how to show search results in the same panel of jframe to where search field... application i need to show search results in the same panel of jframe to where search field and button is present . please Sir, send me the code
how to show search results in the same panel of jframe to where search field and button is present..
how to show search results in the same panel of jframe to where search field... where i have to show the search result in the same panel of where search field and Button is present .I have code which is doing the same work but when i enter
Advertisements
Displaying search results in same panel of gridview in same jframe window.
Displaying search results in same panel of gridview in same jframe window.  Hello Sir, I have a search frame window from which we can search and see the results in the same panel of the Jframe in Gridview Jtable
Displaying search results in same panel of gridview in same jframe window.
Displaying search results in same panel of gridview in same jframe window.  Hello Sir, I have a search frame window from which we can search and see the results in the same panel of the Jframe in Gridview Jtable
How to show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button to jtable  Hello Sir, I made search button with textfield... and show multiple identical rows from database on clicking search button
How to show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button to jtable  Hello Sir, I made search button with textfield... and show multiple identical rows from database on clicking search button
How to show multiple identicle rows from database on clicking search button to jtable
How to show multiple identicle rows from database on clicking search button to jtable  Hello Sir, I made search button with textfield... and show multiple identical rows from database on clicking search button
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
How to open textfields in the the same panel of the jframe by selcting from dropdown menu option ...
How to open textfields in the the same panel of the jframe by selcting from... the textfields and submit button in the same panel of the jframe window . Below is my... and i have to show textfields and submit button on the basis of the selection
how to get data using dropdownlist, textbox and search button in jsp
how to get data using dropdownlist, textbox and search button in jsp  Hi, I want to display data using jsp,javascript and mysql. My Q. is If i select...' in textbox and click on search button it should show me all the title names
How to search the selected item in row table using radia button in JSP?
How to search the selected item in row table using radia button in JSP?  How to search the selected item in row table using radia button in JSP
ModuleNotFoundError: No module named 'google-search-results'
: No module named 'google-search-results' How to remove the ModuleNotFoundError: No module named 'google-search-results' error? Thanks   Hi...ModuleNotFoundError: No module named 'google-search-results'  Hi
ModuleNotFoundError: No module named 'google-search-results'
: No module named 'google-search-results' How to remove the ModuleNotFoundError: No module named 'google-search-results' error? Thanks   Hi...ModuleNotFoundError: No module named 'google-search-results'  Hi
ModuleNotFoundError: No module named 'google-search-results-serpwow'
: No module named 'google-search-results-serpwow' How to remove the ModuleNotFoundError: No module named 'google-search-results-serpwow' error...ModuleNotFoundError: No module named 'google-search-results-serpwow'  
How to hide and show some field on a radio button click
How to hide and show some field on a radio button click  This is my... and cheque number label and textbox to be invisible when by cash radio button is clicked.and they should be visible when by cheque radio button is clicked. I have
how to display data from database according to entered value in search field
it to be the same with what i have entered in the search field. let say i entered 17...how to display data from database according to entered value in search... :)   Here is a simple JSP search application where user is allowed to enter
save links clicked in search engine results
search engine results in my program(any search engine).ie suppose i give a keyword,i need the results returned by that search engine.from the returned results... found how to access the search page of search engines(yahoo) from javascript
display results on same jsp page
display results on same jsp page  is there any method to display search results from database on the same jsp page where i give the inputs using struts 1.2
display results on same jsp page
display results on same jsp page  is there any method to display search results from database on the same jsp page where i give the inputs using struts 1.2
display results on same jsp page
display results on same jsp page  is there any method to display search results from database on the same jsp page where i give the inputs using struts 1.2
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
search
search  how to develop search box and how to retrive data from database..   Please visit the following link: Search box
How to perform search using AJAX?
and hit button, there is a Ajax call to retrieve search results from a simple txt...How to perform search using AJAX?  Hi, I have following HTML code...; <td><label for="status">Search Status</td> <td><input
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
Search index
Search index  how to write code for advanced search button
ModuleNotFoundError: No module named 'odoo8-addon-web-listview-show-advanced-search'
: ModuleNotFoundError: No module named 'odoo8-addon-web-listview-show-advanced-search...-web-listview-show-advanced-search' error? Thanks   Hi... odoo8-addon-web-listview-show-advanced-search python with following command: pip
enabling parts of a search button based on the ssn boxes filled.
enabling parts of a search button based on the ssn boxes filled.  I want to do an AJAX program to search a particular ssn. Currently I have ssn field with 3 text boxes and a search button to search the particular ssn. I want
how to show hyperlink website on the same page
how to show hyperlink website on the same page  dear sir: i need to know how can you show a webiste on the same page. for example i want to show... on the same page weather it is left aligned or right. i read somewhere that you
multiple records on same panel
multiple records on same panel  i have multiple access of records and i want to display all of them at one panel.Each time a new panel opens for a keyrecord , i want just to show records on same panel or frame, whatever u can
How to include website in google search?
How to include website in google search?  Does anyone has idea about how to include a website into Google Search?   Visit the given Google website link on how to oiptimize or submit your website to Google. http
How to using Binary Search Array Java ?
How to using Binary Search Array Java ?  Hi, I am beginners in Java... functions. The problem is that how to use binary search array in Java. Please give any online reference show that i will implement the binary search array in Java

Ads