Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT Displaying search results in same panel of gridview in same jframe window.
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vikas pandey
Displaying search results in same panel of gridview in same jframe window.
0 Answer(s)      2 years and 3 months ago
Posted in : Swing AWT


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 format ...

Jtable is being constructed dynamically based on columns of database query....

But when we execute search for the second time database table columns are also being added alongwith the search result fields in the dynamically created Jtable Gridview ....

Sir, According to my requirement i need results in the Jtable gridview format in the sam epanel of jframe window .But when i execute second search first search result should be deleted and current search result should be displayed in the jpanel of jframe window....

import java.sql.*; import java.util.*; import java.awt.event.*; import java.lang.String; 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();

    lab.setBounds(10,10,100,20);
    t.setBounds(120,10,100,20);
    b.setBounds(120,40,80,20);
   pane.setBounds(10,90,480,170);
 f.add(lab);
    f.add(t);
    f.add(b);
    f.add(pane);
   f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
   pane.setVisible(false);
    f.setSize(600,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/techsoft", "root", "techsoft");
       Statement st=con.createStatement();
       ResultSet rs=st.executeQuery("select * from ankur 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);



        Vector str=columnNames;

         DefaultTableModel model=new DefaultTableModel(data,str);
         table.setModel(model);

         pane.setVisible(true);
        }
        }

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



}

}


Advertisement
View Answers

Related Tutorials/Questions & Answers:
Displaying search results in same panel of gridview in same jframe window.
Displaying search results in same panel of gridview in same jframe window... search and see the results in the same panel of the Jframe in Gridview Jtable... in the Jtable gridview format in the sam epanel of jframe window .But when i execute
Displaying search results in same panel of gridview in same jframe window.
Displaying search results in same panel of gridview in same jframe window... search and see the results in the same panel of the Jframe in Gridview Jtable... in the Jtable gridview format in the sam epanel of jframe window .But when i execute
Advertisements
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... ,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
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... only current search results alongwith the column as header of gridview
How to open textfields in the the same panel of the jframe by selcting from dropdown menu option ...
the textfields and submit button in the same panel of the jframe window . Below is my code which is displaying textfields in the other jframe. KIndly help me sir...How to open textfields in the the same panel of the jframe by selcting from
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
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
Displaying error on the Same form
Displaying error on the Same form  I want to display the errors on the same form(Top of the form) after validation. I am used Div element and Table.... There is a root Div element they are using for Window purpose. I tried to resize it using DOM
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
Displaying the same image in a JPanel and using scroll - HELP - Java Beginners
Displaying the same image in a JPanel and using scroll - HELP  I hope... JFrame implements ActionListener { private Dimension area; //indicates area...){} private static void createAndShowGUI() { //Create and set up the window
get data in pop up window droplists and on selecting data in the same show a grid table with related datas
get data in pop up window droplists and on selecting data in the same show... a pop up window appears with two drop down lists and a button. One of the drop... on the button I need to get the list of hotels in a table grid format on the same
displaying data based on criteria from 2 tables having same type of data - Java Beginners
displaying data based on criteria from 2 tables having same type of data ... to process search criteria without having a form. I have recently read up about...) to process a search. The search will have following features:- 1
Displaying Error pages in results tree in jmeter
Displaying Error pages in results tree in jmeter   Displaying Error pages in results tree in jmeter
STRUTS-display search results - Struts
STRUTS-display search results  Hii, I am a beginner in struts..I want to retrieve few records from database and display in jsp page.First i tried... them in jsp.. Search Results
Displaying checked checkbox in same page as well as print on another page ....also add next pages cheches checkbox into previous list
Displaying checked checkbox in same page as well as print on another page... same checkboxes. So, from your above code, i can display selected checkbox on same page. It works... But when i go to another page link containing same format
Same day travel deals
Same day travel deals  Hi, Can anyone compare same day travel deals with different travel packages? Thanks
Servlets errors in same page.
Servlets errors in same page.  How do I display errors list in the same page where a form field exists using servlets...........i.e. without using JSP? Please explain with a simple username password program
populating a screen on the same page
populating a screen on the same page  i'm making a time table in jsp. i have put button on each slot.if a person click on that slot it'll redirect to a new page which will help them to choose the subject and faculty through drop
save links clicked in search engine results
save links clicked in search engine results  hello i need to access 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
more Submit buttons in the same form
more Submit buttons in the same form  Can I have two or more Submit buttons in the same form
Two or more actions in the same form
Two or more actions in the same form  Can I have two or more actions in the same form
login for different user in the same page
login for different user in the same page  how can i do the login for different user in the same page throug jsp
add same tables in jsp page
add same tables in jsp page  hi I have a table in my jsp page with data, now I want to add same copy of table without its default value in same page whenever I click add more table, how do I do
Agra same day car rental
Agra same day car rental  Hi, I want to see the Taj Mahal but just wondering where to book car on rental for the same day trip to Taj Mahal? Thanks
same data inserted 2 times
same data inserted 2 times  thanks for reply, i know the insert command. but same data inserted 2 times.where is the problem i cannot understood
Retrieve all the students in the same year(Java ArrayList)?
in the same year search = null; search...Retrieve all the students in the same year(Java ArrayList)?  FoundStudents.jsp year- parameter I receive from a form search- is an object of type
Same Day Agra Tour
Same Day Agra Tour We are offering Same Day Agra Tour that enables you to see the various tourists attractions in Agra in a single day. The Same Day Agra.... Itinerary for Same Day Agra Tour 0500 Hrs: Pick up from Delhi Hotel 0830 Hrs
Hash value is not same - Java Beginners
Hash value is not same  Hi, I've two Excel files with same data. One is in Excel 2003 (.xls) format and other one is in Excel 2007 (.xlsx) format... 2003 files is not same as the hash value of Excel 2007 file. What might
DOJO+Creating button of same size.
DOJO+Creating button of same size.  I am trying to create two buttons in DOJO of equal size. But the size of the buttons varies depending upon the name of the button that will get displayed. I tried by giving a class atribute
Advertisements
 

 

 

DMCA.com