Results 1 to 10 of 10
Thread: Using JtabbedPane
- 03-24-2010, 10:37 AM #1
Member
- Join Date
- Apr 2009
- Posts
- 29
- Rep Power
- 0
-
Why not add the menu bar to the JFrame (or other root pane)? If not, then you can add it BorderLayout.NORTH to whatever Container is holding your JTabbedPanes.
- 03-24-2010, 11:19 AM #3
Member
- Join Date
- Apr 2009
- Posts
- 29
- Rep Power
- 0
Actually I nedd to customize mytabbed pane in the same way as in eclipse .
I need to select a tab and display the corresponding menuBar . If I add the menu bar to the frame it won't work out with the same look and feel.
-
I have Eclipse, and I'm still not sure what you mean here. In my version of Eclipse, the menubar is part of the main displayed window (their equivalent of a JFrame), not part of the tabbed pane.
edit: I think I see what you mean. You want a menu bar below the tabs. Then you need to add a JMenuBar to the JPanels that the JTabbedPane tabs hold.Last edited by Fubarable; 03-24-2010 at 11:26 AM.
- 03-24-2010, 11:27 AM #5
Member
- Join Date
- Apr 2009
- Posts
- 29
- Rep Power
- 0
Hi ..
In eclipse we have the lower tabbed pane where we have the console pane in that on selecting console tab you get to see a toolbar on the right . And in the simlar manner on selecting different tabe u get different toolbar Iwant to achieve the same using menubar.
- 03-24-2010, 11:34 AM #6
see API for methods of JTabbedPane.on selecting console tab you get to see a toolbar on the right . And in the simlar manner on selecting different tabe u get different toolbar
getSelectedIndex()
setSelectedIndex()
removeTabAt(int index)
addTab
to accomplish ur task from menubar.
- 03-24-2010, 11:49 AM #7
Member
- Join Date
- Apr 2009
- Posts
- 29
- Rep Power
- 0
I am not able to find a way to add menu bar at the extreme right on the tabbed pane directly . If I use add method it adds the menu as a tab which I don't want .
-
You want to add menu icons to the JTabbedPane's tab bar, the narrow rectangle that holds the tabs themselves. I don't know how to do this in Swing or if it's possible. Let's see if any of the Swing pros come across this thread and can give you some advice.
- 03-24-2010, 12:08 PM #9
u can add menubar to a panel, using appropriate layout.to add menu bar at the extreme right on the tabbed pane directly
then add that panel to tabbedpane..
very closer to the above suggested,
es.Why not add the menu bar to the JFrame (or other root pane)? If not, then you can add it BorderLayout.NORTH to whatever Container is holding your JTabbedPan
- 03-24-2010, 12:24 PM #10
Can't be done directly, but this posting of mine shows a way to fake it.
How to add a jbutton to tabbed pane headder?
I've modified the example for a JMenu in place of a JButton.
dbJava Code:import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class TabbedPanePlusButton { static final int NUM_TABS = 5; public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new TabbedPanePlusButton().makeUI(); } }); } public void makeUI() { final JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.setPreferredSize(new Dimension(400, 400)); for (int i = 0; i < NUM_TABS; i++) { JPanel panel = new JPanel(); panel.setName("tab" + (i + 1)); panel.add(new JLabel("This is panel " + (i + 1))); 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("Click"); //button.setPreferredSize(new Dimension(button.getPreferredSize().width, // (int) tabBounds.getHeight() - 2)); JMenu menu = new JMenu("Menu"); menu.setPreferredSize(new Dimension(menu.getPreferredSize().width, (int) tabBounds.getHeight() - 2)); for (int i = 0; i < NUM_TABS; i++) { JMenuItem item = new JMenuItem("Tab " + (i + 1)); final int j = i; item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tabbedPane.setSelectedIndex(j); } }); menu.add(item); } JMenuBar bar = new JMenuBar(); bar.add(menu); //glassPane.add(button, gbc); glassPane.add(bar, gbc); frame.setLocationRelativeTo(null); frame.setVisible(true); } }
edit Note that it is your responsibility to see that the tabs and the menu don't overlap. The menu being added to the glass pane means that it will always be displayed over the tabbed pane.Last edited by DarrylBurke; 03-24-2010 at 12:36 PM.
Similar Threads
-
[SOLVED] How To Freeze Tab/s from JTabbedPane
By javanewbie in forum New To JavaReplies: 2Last Post: 06-10-2009, 09:42 AM -
Traversing a JTabbedPane
By Inks in forum AWT / SwingReplies: 12Last Post: 03-11-2009, 05:15 AM -
How to use JTabbedPane
By Java Tip in forum javax.swingReplies: 0Last Post: 06-27-2008, 07:50 PM -
Help with JTabbedPane
By lenny in forum SWT / JFaceReplies: 1Last Post: 08-07-2007, 06:18 AM -
Same component on all JTabbedPane
By java_novice in forum AWT / SwingReplies: 4Last Post: 08-06-2007, 09:09 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks