Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking a vertical scrolling JFrame with FLowLayout
    primarykey
    data
    text
    <p>I am writing a simple application, an equation system solver. The basic idea behind it is to get the number of variables in the system from user and create that many JTextFields dynamically followed by a button, to solve the system.</p> <p>In my endeavor to achive it, I am struggling to set the vertical scroll bar.</p> <p>What happens is, the layout gets all messed up after the JScrollPane is used.</p> <p>I've used <a href="https://stackoverflow.com/questions/5928514/how-can-i-scroll-my-jframe-using-the-jscrollbar">this</a> as a guide and tried doing it this way, with VERTICAL_ALWAYS AND HORIZONTAL_NEVER, but it doesn't work.</p> <p>The controls are placed side ways, instead of one-after-the-other from top to bottom.</p> <p>How to achieve this ?</p> <pre><code>public class SolverUserInterface implements ActionListener{ private JFrame solverUI; private JPanel panel; private JLabel lbl[]; private JTextField eq_Fields[]; public SolverUserInterface(int Count) { // TODO Auto-generated constructor stub solverUI = new JFrame("Solver"); solverUI.setSize(405, 137); solverUI.setResizable(false); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); solverUI.setLocation(dim.width/2-solverUI.getSize().width/2, dim.height/2-solverUI.getSize().height/2); solverUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel = new JPanel(); panel.setLayout(new FlowLayout()); lbl = new JLabel[Count]; eq_Fields = new JTextField[Count]; for(int i = 0; i &lt; Count; i++){ lbl[i] = new JLabel("Equation "+(i+1)+" : "); eq_Fields[i] = new JTextField(26); panel.add(lbl[i]); panel.add(eq_Fields[i]); } JButton btnSolve = new JButton("Solve Equations!"); panel.add(btnSolve); btnSolve.addActionListener(this); /*This is the part concerned*/ JScrollPane jp = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); solverUI.add(jp); solverUI.revalidate(); } public void ShowUserInterface(){ solverUI.setVisible(true); } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub } } </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.
 

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