Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am unable to reproduce the effect you describe on 1.6; you might try the <a href="http://sscce.org/" rel="nofollow noreferrer">sscce</a> below on 1.7. Note, several suggestions for your example:</p> <ul> <li><p>Avoid <code>setXxxxSize()</code>, as discussed <a href="https://stackoverflow.com/q/7229226/230513">here</a>. If you just want a 30 pixel high bar in <code>SOUTH</code>, override <code>getPreferredSize()</code> as shown below. If you later decide to add components, you'll need to add a layout manager.</p> <pre><code>@Override public Dimension getPreferredSize() { return new Dimension(0, 30); } </code></pre></li> <li><p>Use <code>pack()</code> to let the <code>Window</code> adopt the preferred sizes of the enclosed components. I've added an arbitrary size <code>JPanel</code> to the <code>CENTER</code>; resize the frame to see how the bar grows horizontally in <code>SOUTH</code>.</p></li> <li><p>Swing GUI objects should be constructed and manipulated <em>only</em> on the <a href="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html" rel="nofollow noreferrer">event dispatch thread</a>.</p></li> </ul> <p><img src="https://i.stack.imgur.com/31eWW.png" alt="BottomBar"></p> <pre><code>import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; /** @see https://stackoverflow.com/a/13610367/230513 */ public class Main { public static void main(String args[]) { EventQueue.invokeLater(new Runnable() { @Override public void run() { JFrame frame = new JFrame("BottomBar"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JPanel() { @Override public Dimension getPreferredSize() { return new Dimension(320, 240); } }, BorderLayout.CENTER); frame.add(new BottomBar(), BorderLayout.SOUTH); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); } }); } private static class BottomBar extends JComponent { @Override public Dimension getPreferredSize() { return new Dimension(0, 30); } @Override protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); GradientPaint gradient = new GradientPaint( 0, 0, new Color(185, 185, 185), 0, getHeight(), new Color(151, 151, 151)); g2.setPaint(gradient); g2.fillRect(0, 0, getWidth(), getHeight()); g2.setColor(new Color(64, 64, 64)); g2.drawLine(0, 0, getWidth(), 0); g2.setColor(new Color(215, 215, 215)); g2.drawLine(0, 1, getWidth(), 1); } } } </code></pre>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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