I am working under Windows OS, the default behavior while resizing application under windows is to bring the menu downwards if it doesn't fit the size. (Please refer the attachment Expected.jpg) where i tried resizing the Eclipse IDE window which shows the menu perfectly and all the menu's are accessible
Wherein if i try to resize the JFrame which i have created using the code below
I can see that the menu is no longer usable (Please refer Result.jpg in attachment). How can i prevent this from happening. I tried using FlowLayout on JMenuBar but still i can't see any difference.
and that one seemed to work if i have only the menu aligned in the left of the JFrame. When i tried adding a JLabel onto JMenuBar using Box.createHorizontalGlue() to align only the JLabel to the right the custom layout code is not working as it uses the FlowLayout wherein the Glue will work perfectly under BoxLayout only. So any idea how to over come this situation.
Create a panel that contains 2 menubars. One that can wrap and one that can't.
Something like the following. This examples uses the Wrap Layout which probably does the same thing as your CustomJMenuBarLayout, but as the class name implies it is more general. Choose whichever layout you want to use.
I tried out your code and found that it is working perfectly fine with the JMenu Help laid at the right end of JMenuBar. But, when i tried to change your code to meet my requirement of placing a JLabel at the right end i end up with another problem.
I took your code and then replaced Help - JMenu with a JLabel
When i run this code initially it came up well (Attachment Step1.jpg) then i tried resizing to increase the size of JFrame which also worked perfectly (Attachment Step2.jpg) then i tried resizing to reducing the size of JFrame and found that the JLabel which was added is causing the JMenu to disappear(Attachment Step3.jpg)
I tried the same operation with native windows application which does a reverse case of hiding the Label. So can you tell me your suggestion to make the same for this JFrame as well. If i try to reduce the size of the JFrame then the JLabel can be hidden but the JMenu should appear.
And finally you got a nice blog post explaining the issue and can i use your WrapLayout.java in my code provided i will include your blog URL in the code.
Joined: Jun 13, 2009
Add a ComponentListener to the panel. On the componentResized() event you need to do a calculation that determines it the label should be visible or not based on the width of the panel the label and the menu items.