Note that there are some explanatory texts on larger screens.

plurals
  1. POjava swing layout of two components
    primarykey
    data
    text
    <pre><code> +--------------------------------------------+ | +-------+ +----------+| | | +---+ | | +-----+ || | | | A | | | | B | || | | +---+ | | +-----+ || | +-------+ +----------+| +--------------------------------------------+ ^ | | Center </code></pre> <p>Background: <strong>I have</strong></p> <ul> <li>a JButton ("A"), size 50x25, within a JPanel (FlowLayout.CENTER)</li> <li>a JLabel ("B"), size 100x25, within a JPanel (FlowLayout.RIGHT)</li> <li>the two JPanels are in a JPanel</li> </ul> <p>Desired Result: <strong>I want</strong></p> <ul> <li>The JButton "A" to always be centered horizontally, </li> <li>The JLabel "B" to always be flush right.</li> </ul> <p>Thing I've tried: <strong>These didn't work for me</strong></p> <ul> <li>BorderLayout is not working for me because JButton "A" is shifted LEFT:</li> <li><p>I'd prefer not to put an invisible component WEST to undo the shift</p> <pre><code>+--------------------------------------------+ | +-------+ +----------+| | | +---+ | | +-----+ || | | | A | | | | B | || | | +---+ | | +-----+ || | +-------+ +----------+| +--------------------------------------------+ ^ ^ | | | | | Center | Shifted Left </code></pre></li> <li><p>GridLayout won't work because I don't want the "A" and "B" to be expanded</p></li> </ul> <p>Appreciate any suggestions! </p> <p>p.s.</p> <p>The JButton/JLabels are each inside of their own JPanels because WITHOUT the Jpanel, BorderLayout.CENTER expands the JButton across the entire width of the major panel (up to the left edge of the JLabel). The JPanels are not needed/critical to the statement of the problem</p> <p><strong>Conclusion</strong>:</p> <ul> <li>I went with "Hovercraft Full Of Eels" answer posted below. Thanks! </li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload