Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are so many things that could be going wrong, without more code it's difficult to pin point an exact problem...</p> <p>A few things jump to mind...</p> <ul> <li>Use appropriate layout managers, even compound layout managers</li> <li>Provide additional information to the <code>JTextArea</code> to allow it to define a usable space, such as rows and columns</li> <li>Add the <code>JTextArea</code> to a <code>JScrollPane</code> to ensure that it doesn't suddenly occupy more space then is actually available</li> </ul> <p><img src="https://i.stack.imgur.com/XxbKj.png" alt="enter image description here"></p> <pre><code>import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JProgressBar; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class TestLayout21 { public static void main(String[] args) { new TestLayout21(); } public TestLayout21() { EventQueue.invokeLater(new Runnable() { @Override public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { } JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); } public class TestPane extends JPanel { public TestPane() { setLayout(new BorderLayout()); JPanel actions = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.fill= GridBagConstraints.HORIZONTAL; actions.add(new JButton("Walk"), gbc); actions.add(new JButton("Run"), gbc); actions.add(new JButton("Jump"), gbc); actions.add(new JButton("Eat"), gbc); actions.add(new JButton("Drink"), gbc); add(actions, BorderLayout.WEST); add(new JProgressBar(), BorderLayout.SOUTH); JTextArea textArea = new JTextArea(20, 40); add(new JScrollPane(textArea)); } @Override public Dimension getPreferredSize() { return new Dimension(200, 200); } } } </code></pre>
 

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