
10-07-2008, 01:52 PM
|
|
Member
|
|
Join Date: Jun 2008
Posts: 20
Rep Power: 0
|
|
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.
|
|

10-07-2008, 03:00 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
|
|
|
Do you have any code for this project?
|
|

10-07-2008, 04:13 PM
|
|
Member
|
|
Join Date: Jun 2008
Posts: 20
Rep Power: 0
|
|
|
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.
|
|

10-07-2008, 07:56 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
|
|
|
You can add the button to the panel and then add the panel.
|
|

10-10-2008, 07:32 AM
|
|
Member
|
|
Join Date: Jun 2008
Posts: 20
Rep Power: 0
|
|
|
Actually I dont need the button in the pannel. I need the button in the tabbed pane itself.
Thank you.
|
|

10-11-2008, 02:10 AM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,326
Rep Power: 8
|
|
|
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?
|
|

10-11-2008, 04:36 AM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
|
|
|
Does the API doc for tabbed pane have an add() method? What does it say?
|
|

10-13-2008, 08:02 AM
|
|
Member
|
|
Join Date: Jun 2008
Posts: 20
Rep Power: 0
|
|
|
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.
|
|

10-13-2008, 10:56 AM
|
 |
Senior Member
|
|
Join Date: Sep 2008
Location: Madgaon, Goa, India
Posts: 711
Rep Power: 2
|
|
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
|
|

10-13-2008, 03:30 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
|
|
|
Very nice.
|
|

10-14-2008, 02:57 PM
|
 |
Senior Member
|
|
Join Date: Sep 2008
Location: Madgaon, Goa, India
Posts: 711
Rep Power: 2
|
|
Thanks Norm
Originally Posted by Norm
|
|
Very nice.
|
Very nice for me that someone appreciated the effort
Seems to have been wasted on the OP thoiugh
db
|
|

10-15-2008, 07:34 AM
|
|
Member
|
|
Join Date: Jun 2008
Posts: 20
Rep Power: 0
|
|
|
Thank you Darryl,
This is what I expected, very cool.
Thank you.
|
|

10-15-2008, 09:16 PM
|
 |
Senior Member
|
|
Join Date: Sep 2008
Location: Madgaon, Goa, India
Posts: 711
Rep Power: 2
|
|
|
Your thanks are appreciated, but now it's time you start to solve your problems yourself.
db
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +2. The time now is 05:30 AM.
|
|