1

I have this code...it's working, but I'd like to open a new JTable and show results rather than having a JTable inside a JFrame. I've been struggling to find a solution but couldn't, can anyone help me?

try {
    String SQL ="SELECT * From Giocatori Where lower(Nome)= lower(?)";
    PreparedStatement preparedStatement = con.prepareStatement(SQL);
    String nome= ricercaetichetta.getText();
    preparedStatement.setString(1, nome.toLowerCase());
    //SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy");

    // System.out.println(nome); 
    rs = preparedStatement.executeQuery();
    // risultati.append("Codice Fir | Nome | Cognome | Scadenza Visita"+"\n"+"\n");
    tabella.setModel(DbUtils.resultSetToTableModel(rs));

enter image description here <-- As you can see, I have to insert JTable before the query. I'd like to make it appear only after I click on the button...(in the same frame or another).

Darwin von Corax
  • 5,201
  • 3
  • 17
  • 28
CCC
  • 170
  • 1
  • 15
  • *"I'd like to make it appear only after i click on the button."* Alternatives: 1) Create the table at start-up. Fill the model on button click. 2) Create the table at start-up, add it as one card of a `CardLayout` and flip to the table on button click. – Andrew Thompson Mar 26 '16 at 23:31
  • *"(in the same frame or another)"* BTW - See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Mar 26 '16 at 23:45
  • Thank you Andrew Thompson! After reading " The Use of Multiple JFrames, Good/Bad Practice?" I tried to keep it simple. I added a jPanel.setVisible(false), put the table into it and then, when i click on the button i set: jPanel1.setVisible(true); – CCC Mar 27 '16 at 01:29
  • *"I tried to keep it simple."* Simple would be the two suggestions I made, while you went a third way.. – Andrew Thompson Mar 27 '16 at 01:34
  • I tried to use CardLayout but didn't work(i'm a beginner by the way). Setting a panel to visible has been the easiset way to do this in my opinion...I'll try to understand how to use CardLayouts too. – CCC Mar 27 '16 at 12:19
  • *"I tried to use CardLayout but didn't work"* The best approach would be to find out why it failed. Playing with visibility of components is a hack. – Andrew Thompson Mar 27 '16 at 13:03
  • 1
    Got it...will do it, thanks for your time Andrew! – CCC Mar 27 '16 at 13:12

1 Answers1

1

use setvisible() in build method u can hide or show the tabele. using that method u can do what u want.
setvisble examples

Sandun Chathuranga
  • 2,242
  • 2
  • 13
  • 27