File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Help in tabbedpane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help in tabbedpane" Watch "Help in tabbedpane" New topic
Author

Help in tabbedpane

pooja prabhu
Ranch Hand

Joined: Sep 23, 2012
Posts: 33
Guys i have created a tabbed pane with tabs whose values i have retrieved from database. and i have attached a panel array to it in which i have created table.Now When I change my tab it doesnt show table with records

Please help

<code>
public void stateChanged(ChangeEvent e) {


String name;
name=tab.getTitleAt( tab.getSelectedIndex());
System.out.println(name);
int ind=tab.getSelectedIndex();
panels[ind].revalidate();
panels[ind].repaint();




if(name.equals("Direct"))
{
try{


chooser=new JFileChooser();
panels[ind]=new JPanel();

chooser.setBounds(150, 100, 80, 32);
panels[ind].add(chooser);
panels[ind].revalidate();
panels[ind].repaint();
}
catch(Exception mn)
{
System.out.println(mn);
}
}
else
{
try{

scroll.removeAll();
table.removeAll();
// scroll.revalidate();
// scroll.repaint();
// table.revalidate();
// table.repaint();
System.out.println(temp);


//
try
{

Statement stmt =(Statement) MySqlConnection.conn().createStatement();
String sql1="select * from event_type";
ResultSet rset=(ResultSet) stmt.executeQuery(sql1);

while(rset.next())
{
event_desc= rset.getString("event_type_desc");

String j;
j=tab.getTitleAt( tab.getSelectedIndex());

try

{
data.clear();
String event="";
Statement stmt5 =(Statement) MySqlConnection.conn().createStatement();
String sql5="select * from event_master,person_details,event_type where event_type.event_type_desc='"+j+"' AND person_details.person_name like'"+temp+"%'AND event_master.event_type_id=event_type.event_type_id AND event_master.person_id=person_details.person_id";
try{
ResultSet rset5=(ResultSet) stmt5.executeQuery(sql5);
while(rset5.next())
{
event = rset5.getString("event_type_desc");
}



}
catch(Exception ertd)
{
System.out.println(ertd);
}

Statement stmt0 =(Statement) MySqlConnection.conn().createStatement();
String sql0="select * from event_master,person_details,event_type where event_type.event_type_desc='"+j+"' AND person_details.person_name like'"+temp+"%'AND event_master.event_type_id=event_type.event_type_id AND event_master.person_id=person_details.person_id";

ResultSet rset0=(ResultSet) stmt0.executeQuery(sql0);


if (j.equals(event))
{

model = new DefaultTableModel(data, headers);
headers.add("Event ID");
headers.add("Person Name");
headers.add("Event Date");
headers.add("Event Message");

table=new JTable(data,headers);
table.setPreferredScrollableViewportSize(new Dimension(1300,350));
setColumnWidth(table.getColumnModel().getColumn(0), 500);
setColumnWidth(table.getColumnModel().getColumn(1), 500);
setColumnWidth(table.getColumnModel().getColumn(2), 500);
setColumnWidth(table.getColumnModel().getColumn(3), 500);

scroll = new JScrollPane(table);

scroll.setBounds(30, 50, 1400, 340);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
getContentPane().add(scroll);


panels[ind].add(scroll) ;

for(int rowCount=table.getRowCount(); rowCount>0; rowCount--)
{
model.removeRow(rowCount-1);
}


data.clear();
while(rset0.next())

{
d=new Vector();
d.add(rset0.getString("event_id"));
d.add(rset0.getString("person_name"));
d.add(rset0.getString("event_on_date"));
d.add(rset0.getString("event_message"));
d.add("\n\n\n\n\n\n\n");
data.add(d);

}
table.addNotify();
table.setModel(model);
table.revalidate();
table.repaint();
table.setEnabled(false);



}
}
catch(Exception etr)
{
System.out.println(etr);
}
// Counter++;
// f++;
}
}

catch(Exception et)
{
System.out.println(et);
}
//
}

catch(Exception erd)
{
System.out.println(erd);
}

}


}

}



);
</code>
rohan sethi
Ranch Hand

Joined: Dec 14, 2012
Posts: 34

Pooja, Don't block the EDT, try to wrap NoN-GUI code in SwingUtilities.invokeLater() or SwingUtilities.invokeAndWait() .Or try using a new thread for DB operations.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help in tabbedpane