[SOLVED] HorizontalGlue has no effect in JMenuBar

Discuss here any questions about the WebLaF library.
Bugs can be posted directly to GitHub issues tracker.

[SOLVED] HorizontalGlue has no effect in JMenuBar

Postby petermacgonagan » Thu Sep 04, 2014 3:35 pm

Hello,

I'm trying to put an HorizontalGlue in my menu but when Weblaf is installed, the horizontalGlue has no effect.

Here is the minimal code:
Code: Select all
        JMenuBar jMenuBar = new JMenuBar();

        jMenuBar.add(new javax.swing.JMenu("File"));
        jMenuBar.add(new javax.swing.JMenu("Edit"));
        jMenuBar.add(Box.createHorizontalGlue());
        jMenuBar.add(new javax.swing.JMenu("About"));


TIA :D
petermacgonagan
 
Posts: 9
Joined: Wed Sep 03, 2014 10:57 pm

Re: HorizontalGlue has no effect in JMenuBar or WebMenuBar

Postby mgarin » Fri Sep 05, 2014 2:47 pm

I just checked how that glue works in MetalLookAndFeel - it simply creates spacing component to push next items to the end of menubar, which is basically a pretty ugly workaround.

With WebLaF installed - you don't need to create such additional "workaround" components, you simply need to provide proper layout constraint with the JMenu component when added:
Code: Select all
JMenuBar jMenuBar = new JMenuBar ();
jMenuBar.add ( new javax.swing.JMenu ( "File" ) );
jMenuBar.add ( new javax.swing.JMenu ( "Edit" ) );
jMenuBar.add ( new javax.swing.JMenu ( "About" ), ToolbarLayout.END );

Since JMenuBar with WebLaF installed is using custom ToolbarLayout.

And if you want to support various L&F - you can keep the glue creation:
Code: Select all
jMenuBar.add ( Box.createHorizontalGlue () );

It won't affect anything in WebLaF.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: HorizontalGlue has no effect in JMenuBar

Postby petermacgonagan » Sun Sep 07, 2014 6:36 pm

Oh great! Thank you very much :)
petermacgonagan
 
Posts: 9
Joined: Wed Sep 03, 2014 10:57 pm

Re: HorizontalGlue has no effect in JMenuBar

Postby mgarin » Mon Sep 08, 2014 9:29 am

Marking solved.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg


Return to Questions

Who is online

Users browsing this forum: No registered users and 2 guests

cron