Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8139133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:43:28+00:00 2026-06-06T11:43:28+00:00

I’ve tried several ways to get this to render correctly. I want my logo

  • 0

I’ve tried several ways to get this to render correctly. I want my logo area to hug east as the window is resized, but not to overlap the Western components. The following code does not hug east, which i think makes sense because the the logoArea box does not know it should take up the rest of the horizontal space.

If i add the logoArea directly to the ‘area’ then it hugs east, but will overlap the western components if the window shrinks too much. Any ideas?

 Box box = Box.createHorizontalBox();
 box.add( main );
 for( JComponent item : items ) //western stuff
 {
    box.add( Box.createHorizontalStrut( 8 ) );
    box.add( item );
 }

 //eastern stuff
 Box logoArea= Box.createHorizontalBox();
 logoArea.add( new JLabel( LAF.Icon.png( "CompanyLogo" ) ), BorderLayout.EAST );

 box.add( Box.createHorizontalStrut( 8 ) );
 box.add( logoArea, BorderLayout.EAST );

 JPanel area = new JPanel( new BorderLayout() );
 area.setBorder( BorderFactory.createEmptyBorder( 2, 2, 2, 2 ) );
 area.add( box, BorderLayout.WEST );
 return area;  //dashboard is built

EDIT

To answer @Nitin i’d like it to move left until it reaches the western components, and then stop moving and disapear from the right side.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:43:29+00:00Added an answer on June 6, 2026 at 11:43 am

    I don’t really know any standart layout that would act as you want, but its not hard to create one. Check this small example (cross-shaped paintings displays content and logo bounds):

    public static void main ( String[] args )
    {
        JFrame frame = new JFrame ();
    
        LogoLayout layout = new LogoLayout ();
        frame.setLayout ( layout );
    
        frame.add ( new JLabel ( "Label with same preferred size as text length" )
        {
            protected void paintComponent ( Graphics g )
            {
                super.paintComponent ( g );
    
                g.setColor ( Color.BLACK );
                g.drawLine ( 0, 0, getWidth (), getHeight () );
                g.drawLine ( getWidth (), 0, 0, getHeight () );
            }
        }, layout.CONTENT );
    
        frame.add ( new JComponent ()
        {
            protected void paintComponent ( Graphics g )
            {
                g.setColor ( Color.BLACK );
                g.drawLine ( 0, 0, getWidth (), getHeight () );
                g.drawLine ( getWidth (), 0, 0, getHeight () );
            }
    
            public Dimension getPreferredSize ()
            {
                return new Dimension ( 100, 100 );
            }
        }, layout.LOGO );
    
        frame.setSize ( 700, 500 );
        frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
        frame.pack ();
        frame.setLocationRelativeTo ( null );
        frame.setVisible ( true );
    }
    
    public static class LogoLayout implements LayoutManager
    {
        public String CONTENT = "Content";
        public String LOGO = "Logo";
    
        private Map<Component, String> constraints = new HashMap<Component, String> ();
    
        public void addLayoutComponent ( String name, Component comp )
        {
            constraints.put ( comp, name );
        }
    
        public void removeLayoutComponent ( Component comp )
        {
            constraints.remove ( comp );
        }
    
        public void layoutContainer ( Container parent )
        {
            Insets bi = parent.getInsets ();
            int contentSize = 0;
            int logoSize = 0;
            int maxHeight = 0;
            for ( Component component : parent.getComponents () )
            {
                Dimension ps = component.getPreferredSize ();
                if ( constraints.get ( component ).equals ( CONTENT ) )
                {
                    contentSize = Math.max ( ps.width, contentSize );
                }
                else if ( constraints.get ( component ).equals ( LOGO ) )
                {
                    logoSize = Math.max ( ps.width, logoSize );
                }
                maxHeight = Math.max ( ps.height, maxHeight );
            }
    
            int width = parent.getWidth () - bi.left - bi.right;
            int height = parent.getHeight () - bi.top - bi.bottom;
            for ( Component component : parent.getComponents () )
            {
                if ( constraints.get ( component ).equals ( CONTENT ) )
                {
                    if ( contentSize + logoSize < width )
                    {
                        component.setBounds ( bi.left, bi.top, width - logoSize, height );
                    }
                    else
                    {
                        component.setBounds ( bi.left, bi.top, contentSize, height );
                    }
                }
                else if ( constraints.get ( component ).equals ( LOGO ) )
                {
                    if ( contentSize + logoSize < width )
                    {
                        component
                                .setBounds ( bi.left + width - logoSize, bi.top, logoSize, height );
                    }
                    else
                    {
                        int scaledLogoSize = width - contentSize;
                        if ( scaledLogoSize > 0 )
                        {
                            component.setBounds ( bi.left + width - scaledLogoSize, bi.top,
                                    scaledLogoSize, height );
                        }
                    }
                }
            }
        }
    
        public Dimension preferredLayoutSize ( Container parent )
        {
            Insets bi = parent.getInsets ();
            int contentSize = 0;
            int logoSize = 0;
            int maxHeight = 0;
            for ( Component component : parent.getComponents () )
            {
                Dimension ps = component.getPreferredSize ();
                if ( constraints.get ( component ).equals ( CONTENT ) )
                {
                    contentSize = Math.max ( ps.width, contentSize );
                }
                else if ( constraints.get ( component ).equals ( LOGO ) )
                {
                    logoSize = Math.max ( ps.width, logoSize );
                }
                maxHeight = Math.max ( ps.height, maxHeight );
            }
            return new Dimension ( bi.left + contentSize + logoSize + bi.right,
                    bi.top + maxHeight + bi.bottom );
        }
    
        public Dimension minimumLayoutSize ( Container parent )
        {
            return preferredLayoutSize ( parent );
        }
    }
    

    Is that how you want your LOGO to act when window is getting sized?

    P.S. This way you can also modify the layout anytime you need to add (for example) another specific component location, some gap between logo and content or anything else…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.