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 add tabs to tabbedpane dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "add tabs to tabbedpane dynamically" Watch "add tabs to tabbedpane dynamically" New topic
Author

add tabs to tabbedpane dynamically

pooja prabhu
Ranch Hand

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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Sep 23, 2012
Posts: 33
Thanks michael but i tried by adding tab to dialog box but it isnt working....
pooja prabhu
Ranch Hand

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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1075
    
  10

And EaseUp. PatienceIsAVirtue.

You are creating a JTabbedPane inside a while loop. why?


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
pooja prabhu
Ranch Hand

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

Joined: Oct 16, 2003
Posts: 1075
    
  10

Well...you should create the JTabbedPane instance before the loop starts. You should only add tabs inside the loop.
pooja prabhu
Ranch Hand

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

Joined: Oct 16, 2003
Posts: 1075
    
  10

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

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

Joined: Oct 16, 2003
Posts: 1075
    
  10

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

Joined: Sep 23, 2012
Posts: 33
If i declare tabbed pane in while loop...it displays all the values....that means my query is not wrong.....
pooja prabhu
Ranch Hand

Joined: Sep 23, 2012
Posts: 33
The problem was size of tabbed pane was small...... thanks for helping me...
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4522
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
 
 
subject: add tabs to tabbedpane dynamically
 
Similar Threads
comparing two time strings please help urgent
TIme comparison how do i compare two times urgent please help
How can I solve IllegalArgumentException
jframe not accepting sql query..
'Syntax Error in Query operator' MS Access