Results 1 to 9 of 9
Thread: Changing position of JMenuBar
- 09-16-2010, 09:42 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 40
- Rep Power
- 0
- 09-16-2010, 10:16 PM #2
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
why would you want to do that?
one way could be to create a new panel and ad it to that panel, but it would be not very clean :p
-
Yep, as dinosoep states above, create a new JPanel, have it use BorderLayout, and add the JMenuBar to this JPanel BorderLayout.NORTH.
- 09-16-2010, 11:01 PM #4
I'm curious. Where did you get that? I don't see it in the API.
As far as your requirement is concerned, a JMenuBar is just another JComponent. You can nest your 'active' JMenuBar and another component in another JMenuBar with an appropriate layout, and set the latter to your JFrame.dbJava Code:import java.awt.BorderLayout; import javax.swing.*; public class NestedMenuBar { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new NestedMenuBar().makeUI(); } }); } public void makeUI() { JMenu menu = new JMenu("Menu"); menu.add(new JMenuItem("Item")); JMenuBar innerBar = new JMenuBar(); innerBar.add(menu); JMenuBar outerBar = new JMenuBar(); outerBar.setLayout(new BorderLayout()); outerBar.add(Box.createVerticalStrut(20), BorderLayout.NORTH); outerBar.add(innerBar, BorderLayout.SOUTH); JFrame frame = new JFrame(); frame.setJMenuBar(outerBar); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); frame.setLocationRelativeTo(null); frame.setVisible(true); } }Last edited by DarrylBurke; 09-16-2010 at 11:19 PM.
- 09-16-2010, 11:03 PM #5
Member
- Join Date
- Aug 2010
- Posts
- 40
- Rep Power
- 0
Thank you. I''ll try right now.
- 09-16-2010, 11:13 PM #6
Member
- Join Date
- Aug 2010
- Posts
- 40
- Rep Power
- 0
I just mean that it is possible to position JMenu vertically or horizontally: Vertical menu bar : JMenuBar*«*Swing*«*Java Tutorial
Your code works as I need. Thanks once again.
BTW, I've tried with two JPanel and BorderLayout.NORTH/SOUTH, however it didn't work for me.
-
- 09-17-2010, 12:00 AM #8
Your JPanels didn't have a preferredSize
db
- 09-17-2010, 12:41 PM #9
Member
- Join Date
- Aug 2010
- Posts
- 40
- Rep Power
- 0
Similar Threads
-
Changing binding when changing the underlying model object
By ChrisNY in forum NetBeansReplies: 0Last Post: 08-14-2010, 10:09 AM -
JMenubar option
By navishkumarb in forum New To JavaReplies: 3Last Post: 05-24-2010, 02:03 AM -
Create JMenuBar using DataBase
By arulmozs in forum AWT / SwingReplies: 1Last Post: 11-03-2009, 11:52 AM -
get position in string from caret position
By helloworld111 in forum AWT / SwingReplies: 5Last Post: 02-19-2009, 01:36 AM -
BorderFactory to set position?
By aleplgr in forum AWT / SwingReplies: 2Last Post: 01-30-2008, 12:46 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks