This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Dynamically adding Jpanels to tabs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Dynamically adding Jpanels to tabs" Watch "Dynamically adding Jpanels to tabs" New topic
Author

Dynamically adding Jpanels to tabs

pooja prabhu
Ranch Hand

Joined: Sep 23, 2012
Posts: 33
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

Joined: May 03, 2008
Posts: 4571
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
pooja prabhu
Ranch Hand

Joined: Sep 23, 2012
Posts: 33
Sorry...henceforth i will use code tags
this is my code....


I want to dynamically add Jpanels to tabs.....can anyone help???
 
GeeCON Prague 2014
 
subject: Dynamically adding Jpanels to tabs