hiii..
I got this strange problem.i m refreshing my jframe after every second.This jframe contains a button called addbutton.This addbutton opens another jframe.and that jframe contains a JComboBox .The problem is after every second the JComboBox is getting refreshed.I dont understand why.Before the user gets time to select any item in the combobox..That combobox again goes to the first element.
Can somone pls explain me hw to prevent all this??
Thanks for your time
Java Code:
public class MarketWatch {
static JButton addButton = new JButton("Add");
public static void main(String args[]) {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
showTable();
}
}, 1000, 2000);
}
public static void showTable() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
// DriverManager.registerDriver(new
// oracle.jdbc.OracleDriver());
Class.forName("oracle.jdbc.driver.OracleDriver");
connMarketWatch = DriverManager.getConnection(
"jdbc:oracle:thin:@192.168.0.22:1521:XE", "sk_api",
"sk_api");
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
selectRow();
}
});
} catch (SQLException | ClassNotFoundException e1) {
// TODO Auto-generated catch block
System.out.println("Error in connecting");
e1.printStackTrace();
}
}
public static void selectRow()
{
try
{
JComboBox jremoverows;
JFrame frame = new JFrame();
Dimension screenSize = new Dimension(Toolkit.getDefaultToolkit().getScreenSize());
frame.setPreferredSize(new Dimension(200, 200));
Dimension windowSize = new Dimension(frame.getPreferredSize());
int wdwLeft = 300 + screenSize.width / 2 - windowSize.width / 2;
int wdwTop = screenSize.height / 2 - windowSize.height / 2;
Statement saddtoremoverow = connMarketWatch.createStatement();
ResultSet rsremoverow = saddtoremoverow.executeQuery("select securty_symbol from copy_view_mkt_watch where removerow='remove'");
int j=0;
while(rsremoverow.next())
{
removedObjects[j]=rsremoverow.getString("SECURTY_SYMBOL");
j++;
}
jremoverows = new JComboBox(removedObjects);
AutoCompleteDecorator.decorate(jremoverows);
jremoverows.setEditable(true);
frame.setSize(200,200);
frame.requestFocus();
frame.setAlwaysOnTop(true);
frame.toFront();
frame.setLocation(wdwLeft, wdwTop);
frame.add(jremoverows);
frame.setLayout(new FlowLayout());
frame.setVisible(true);
}
catch(Exception e)
{
e.printStackTrace();
}
}