Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-07-2008, 01:52 PM
Member
 
Join Date: Jun 2008
Posts: 20
Rep Power: 0
Melki is on a distinguished road
Default How to add a jbutton to tabbed pane headder?
I need to have a jbutton in a tabbed pane. Actually i need three tabs in the tabbed pane and a button next to the tabbed pane headder as we see in the eclipse. Kindly help me regarding this.

Thank you.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 10-07-2008, 03:00 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
Do you have any code for this project?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-07-2008, 04:13 PM
Member
 
Join Date: Jun 2008
Posts: 20
Rep Power: 0
Melki is on a distinguished road
Default
Sorry I am struggling with starting the execution. I want to know, is there a way to add button to the tabbed pane. In tabbed pane we usually add panels which will display as tabs. I want to add a button in the place where the the tab icon is displayed.

Thank you.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-07-2008, 07:56 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
You can add the button to the panel and then add the panel.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 10-10-2008, 07:32 AM
Member
 
Join Date: Jun 2008
Posts: 20
Rep Power: 0
Melki is on a distinguished road
Default
Actually I dont need the button in the pannel. I need the button in the tabbed pane itself.

Thank you.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 10-11-2008, 02:10 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,326
Rep Power: 8
Fubarable is on a distinguished road
Default
Quote:
Actually I dont need the button in the pannel. I need the button in the tabbed pane itself.
This doesn't make sense. Norm (I think) is talking about using a JPanel that is held by the tabbed pane, perhaps BorderLayout.CENTER, so that the JPanel actually becomes the tabbed pane, except for the tab. Are you talking about adding a JButton on the tab itself? Could you go into more detail?
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 10-11-2008, 04:36 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
Does the API doc for tabbed pane have an add() method? What does it say?
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 10-13-2008, 08:02 AM
Member
 
Join Date: Jun 2008
Posts: 20
Rep Power: 0
Melki is on a distinguished road
Default
Sorry! if I confused a lot. Here I have attached a image file which will give you a clear idea of my requirement.

FYI: Norm, the API doc for tabbed pane is having an add(component) method.

Thank you.
Attached Images:
File Type: jpg MyWish.jpg (16.7 KB, 31 views)
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 10-13-2008, 10:56 AM
Darryl.Burke's Avatar
Senior Member
 
Join Date: Sep 2008
Location: Madgaon, Goa, India
Posts: 711
Rep Power: 2
Darryl.Burke is on a distinguished road
Default
On the Sun forum, you said "Yes, <link snipped/> this page is the answer."
Swing - How to draw a component on a Panel?

Another way is to add the button to the frame's glass pane, with an appropriate layout, and set the glass pane's visibility.
Code:
public class TabbedPanePlusButton {

   public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {

         @Override
         public void run() {
            new TabbedPanePlusButton().makeUI();
         }
      });
   }

   public void makeUI() {
      JTabbedPane tabbedPane = new JTabbedPane();
      for (int i = 0; i < 3; i++) {
         JPanel panel = new JPanel();
         panel.setName("tab" + (i + 1));
         panel.setPreferredSize(new Dimension(400, 400));
         tabbedPane.add(panel);
      }

      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.add(tabbedPane);
      frame.pack();

      Rectangle tabBounds = tabbedPane.getBoundsAt(0);

      Container glassPane = (Container) frame.getRootPane().getGlassPane();
      glassPane.setVisible(true);
      glassPane.setLayout(new GridBagLayout());
      GridBagConstraints gbc = new GridBagConstraints();
      gbc.weightx = 1.0;
      gbc.weighty = 1.0;
      gbc.fill = GridBagConstraints.NONE;
      gbc.insets = new Insets(tabBounds.y, 0, 0, 15);
      gbc.anchor = GridBagConstraints.NORTHEAST;

      JButton button = new JButton("My Button Position");
      button.setPreferredSize(new Dimension(button.getPreferredSize().width,
            (int) tabBounds.getHeight() - 2));
      glassPane.add(button, gbc);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
   }
}
Note that GridBagLayout isn't the only layour manager you can use to achieve this.

db
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 10-13-2008, 03:30 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
Very nice.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 10-14-2008, 02:57 PM
Darryl.Burke's Avatar
Senior Member
 
Join Date: Sep 2008
Location: Madgaon, Goa, India
Posts: 711
Rep Power: 2
Darryl.Burke is on a distinguished road
Default Thanks Norm
Originally Posted by Norm View Post
Very nice.
Very nice for me that someone appreciated the effort

Seems to have been wasted on the OP thoiugh

db
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 10-15-2008, 07:34 AM
Member
 
Join Date: Jun 2008
Posts: 20
Rep Power: 0
Melki is on a distinguished road
Default
Thank you Darryl,

This is what I expected, very cool.

Thank you.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 10-15-2008, 09:16 PM
Darryl.Burke's Avatar
Senior Member
 
Join Date: Sep 2008
Location: Madgaon, Goa, India
Posts: 711
Rep Power: 2
Darryl.Burke is on a distinguished road
Default
Your thanks are appreciated, but now it's time you start to solve your problems yourself.

db
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tabbed pane using struts 2.x......? prabhurangan Web Frameworks 2 07-19-2008 07:48 AM
Creating a tabbed display with a single tab Java Tip SWT 0 07-07-2008 05:44 PM
Creating a tabbed display with four tabs and a few controls Java Tip SWT 0 07-07-2008 05:43 PM
Layered Pane Demo Java Tip javax.swing 0 06-26-2008 08:44 PM
AWT can we make a Tabbed container? Panchitopro AWT / Swing 0 05-15-2008 11:31 PM


All times are GMT +2. The time now is 05:30 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org