Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

add tabs to tabbedpane dynamically

 
pooja prabhu
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying to add tabs to tabbedpane dynamically from database.......but only first tab i can click...later all are disabled....

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 d= f2.substring(8,10);
String dates=y+"-"+m+"-"+d+" 00:00:00";
try
{
Statement stmt =(Statement) MySqlConnection.conn().createStatement();
String sql="select * from event_master,event_type where event_on_date='"+dates+"'AND event_master.event_type_id=event_type.event_type_id";
ResultSet rset=(ResultSet) stmt.executeQuery(sql);



while(rset.next())

{
System.out.println(i);
event_desc= rset.getString("event_type_desc");

tab=new JTabbedPane();
this.getContentPane().add(tab);

tab.setBounds(i, 100, 1245, 30);

jp1=new JPanel();
jp1.setBounds(0, 140,600,30);
jp1.setBackground(Color.white);

// tab.addTab(event_desc, new JButton("" +event_desc));
tab.addTab(event_desc, jp1);


i=i+105;
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your problem is most likely here

tab=new JTabbedPane();
this.getContentPane().add(tab);

I'd explain further, but it's urgent, so have to post quickly
 
pooja prabhu
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks michael but i tried by adding tab to dialog box but it isnt working....
 
pooja prabhu
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think as i have assigned same panel to all the tabs its giving me error.......can anyone tel me how to assign jpanel dynamically? please....
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch !
Please UseCodeTags (<-click this link) and UseAMeaningfulSubject (<-click this link too) the next time you ask something.
Take some time to go through our HowToAskQuestionsOnJavaRanch.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And EaseUp. PatienceIsAVirtue.

You are creating a JTabbedPane inside a while loop. why?
 
pooja prabhu
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I take value from table and display them as tabs.....so if i have more than one value it wont display outside while loop....
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well...you should create the JTabbedPane instance before the loop starts. You should only add tabs inside the loop.
 
pooja prabhu
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your valuable time..i did as you said....bt while loop gives only last value in database....please help.....
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pooja prabhu wrote:bt while loop gives only last value in database....please help.....

I am unable to understand what this means. Do you mean to say the query returns only one record? In that case, if you think it should return more than one, then, you should examine your query and data.
 
pooja prabhu
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my table name is event_type.....in that table there are 2 fields....id and description.... I access the description field from query and display all the records in that field as tabs......tabs are:anniversary,birthdays and appointments.....This while loop only displays appointments
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pooja prabhu wrote:tabs are:anniversary,birthdays and appointments. This while loop only displays appointments

So, clearly the query brings back only one record. The query does have a where condition, so, you have to check the query.
My suggestion would be to first fix this and then come back to the Swing part later. You can use sop statements to first find if the db code brings back what you think it should.
 
pooja prabhu
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i declare tabbed pane in while loop...it displays all the values....that means my query is not wrong.....
 
pooja prabhu
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem was size of tabbed pane was small...... thanks for helping me...
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pooja prabhu wrote:The problem was size of tabbed pane was small

Don't use setBounds(...) and you won't run into such a problem. Learn how to use layout managers here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic