File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically adding Jpanels to tabs

 
pooja prabhu
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my code....
tab=new JTabbedPane();
p.add(tab);
tab.setBounds(i, 100, 1245, 500);

try

{

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

while(rset.next())
{
event_desc= rset.getString("event_type_desc");
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();


tab.addTab(event_desc, jp1);

i=i+110;

}

tab.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e)
{

int sel = tab.getSelectedIndex();

if(sel ==2)
{

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

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


JScrollPane scroll = new JScrollPane(table);
scroll.setBounds(10, 50, 1245, 300);
getContentPane().add(scroll);
jp1.add(scroll) ;


try
{

SimpleDateFormat simpledate= new SimpleDateFormat("yyyy-MM-dd");
String f2= simpledate.format((java.util.Date) monthView.getDate());
String y= f2.substring(0,4);
String m= f2.substring(5,7);
String dt= f2.substring(8,10);
String dates=y+"-"+m+"-"+dt+" 00:00:00";;

Statement stmt2 =(Statement) MySqlConnection.conn().createStatement();
String sql2="select * from event_master,person_details,event_type where event_master.event_on_date='"+dates+"'AND event_type.event_type_desc='Appointments' AND event_master.event_type_id=event_type.event_type_id AND event_master.person_id=person_details.person_id";
ResultSet rset2=(ResultSet) stmt2.executeQuery(sql2);
while(rset2.next())

{
d=new Vector();
d.add(rset2.getString("event_id"));
d.add(rset2.getString("person_name"));
d.add(rset2.getString("event_on_date"));
d.add(rset2.getString("event_type_desc"));
d.add(rset2.getString("event_message"));
d.add("\n\n\n\n\n\n\n");
data.add(d);
}
table.setModel(model);
table.revalidate();
}

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

}
if(sel ==1)
{

model1 = new DefaultTableModel(data1, headers1);
headers1.add("Event ID");
headers1.add("Person Name");
headers1.add("Event Date");
headers1.add("Event Type");
headers1.add("Event Message");

table1=new JTable(data1,headers1);
table1.setPreferredScrollableViewportSize(new Dimension(1200,430));
setColumnWidth(table1.getColumnModel().getColumn(0), 500);
setColumnWidth(table1.getColumnModel().getColumn(1), 500);
setColumnWidth(table1.getColumnModel().getColumn(2), 500);
setColumnWidth(table1.getColumnModel().getColumn(3), 500);
setColumnWidth(table1.getColumnModel().getColumn(4), 500);


JScrollPane scroll1 = new JScrollPane(table1);
scroll1.setBounds(10, 50, 1245, 300);
getContentPane().add(scroll1);
jp1.add(scroll1) ;


try
{

SimpleDateFormat simpledate= new SimpleDateFormat("yyyy-MM-dd");
String f2= simpledate.format((java.util.Date) monthView.getDate());
String y= f2.substring(0,4);
String m= f2.substring(5,7);
String dt= f2.substring(8,10);
String dates=y+"-"+m+"-"+dt+" 00:00:00";;

Statement stmt2 =(Statement) MySqlConnection.conn().createStatement();
String sql2="select * from event_master,person_details,event_type where event_master.event_on_date='"+dates+"'AND event_type.event_type_desc='Birthdates' AND event_master.event_type_id=event_type.event_type_id AND event_master.person_id=person_details.person_id";
ResultSet rset2=(ResultSet) stmt2.executeQuery(sql2);
while(rset2.next())

{
d1=new Vector();
d1.add(rset2.getString("event_id"));
d1.add(rset2.getString("person_name"));
d1.add(rset2.getString("event_on_date"));
d1.add(rset2.getString("event_type_desc"));
d1.add(rset2.getString("event_message"));
d1.add("\n\n\n\n\n\n\n");
data1.add(d1);
}
table1.setModel(model1);
table1.revalidate();
}

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

I want to dynamically add Jpanels to tabs.....can anyone help???
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pooja prabhu, Christophe Verré told you about the code tags in your last thread. Please go through the links he provided -- all the advice in those sections is geared towards helping you to get better help here (or indeed on any forum!).

In that same thread, I advised you to learn how to use layout managers and to not use setBounds(...). The advice still stands.
 
pooja prabhu
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry...henceforth i will use code tags
this is my code....


I want to dynamically add Jpanels to tabs.....can anyone help???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic