This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resize problem with JMenuBar

 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Result.jpg
JFrame Window
[Thumbnail for Result.jpg]
Expected.jpg
Eclipse IDE Window
[Thumbnail for Expected.jpg]
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally, searching the bug tracker of java revealed a similar issue which i am facing and i tried out the code provided in the bug tracker

Old Java Bug

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.

Here is the updated code which i am trying now
 
Rob Camick
Ranch Hand
Posts: 2475
8
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick - Thanks for your reply

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.
Step1.jpg
Initial Window
[Thumbnail for Step1.jpg]
Step2.jpg
Resize - Increase
[Thumbnail for Step2.jpg]
Step3.jpg
Resize - Decrease
[Thumbnail for Step3.jpg]
 
Rob Camick
Ranch Hand
Posts: 2475
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob i will try out your suggestion.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic