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:
Advertisements
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 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
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
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
Search index
Search index
how to write code for advanced
search button
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
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
Show results in HTML
Show results in HTML Hi. I have a
field in database named stages... as one value, trichy as one value. and i have to
show it in html.
how to do... for a single record. I have to retrieve these data from the
field table. Actually
search filter and JTable
my question is:
how can i make
search data in JTable of java?
i wan to
search... 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