Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a more sensible and usable GUI based on what you seemed to by attempting. Have a look over it.</p> <p><img src="https://i.stack.imgur.com/B4k6V.png" alt="Solver User Interface"></p> <pre><code>import java.awt.*; import javax.swing.*; public class SolverUserInterface { private JFrame solverUI; private JPanel panel; private JLabel lbl[]; private JTextField eq_Fields[]; public SolverUserInterface(int Count) { solverUI = new JFrame("Solver"); solverUI.setLocationByPlatform(true); solverUI.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); panel = new JPanel(new BorderLayout()); JPanel labels = new JPanel(new GridLayout(0,1,5,5)); JPanel fields = new JPanel(new GridLayout(0,1,5,5)); lbl = new JLabel[Count]; panel.add(labels, BorderLayout.LINE_START); panel.add(fields, BorderLayout.CENTER); 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); labels.add(lbl[i]); fields.add(eq_Fields[i]); } JButton btnSolve = new JButton("Solve Equations!"); solverUI.add(btnSolve, BorderLayout.PAGE_END); JScrollPane jp = new JScrollPane( panel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); solverUI.add(jp); solverUI.pack(); Dimension d = solverUI.getSize(); int w = (int)d.getWidth(); int h = (int)d.getHeight(); h = (h&gt;200 ? 200 : h); Dimension shrinkHeight = new Dimension(w,h); solverUI.setSize(shrinkHeight); } public void showUserInterface(){ solverUI.setVisible(true); } public static void main(String[] args) { Runnable r = new Runnable() { @Override public void run() { SolverUserInterface sui = new SolverUserInterface(105); sui.showUserInterface(); } }; SwingUtilities.invokeLater(r); } } </code></pre> <blockquote> <p>Alright, and just one clarification about Pack(). When I use it, the size of the window grows with the increase in the number of fields, but thats not the case when I remove the Pack(). It seems using Pack() doesn't make sense while using the scroll bar.. Am I correct with this conclusion ?</p> </blockquote> <p>A little, but not entirely. </p> <ol> <li>For working reliably, a GUI should be packed <em>or</em> validated. </li> <li>After a frame is packed, it displays as the minimum size needed to display the components (unless it is taller or wider than the screen size). </li> <li>..but then we can take the packed size, use the width it gives us, and set the height shorter.</li> </ol>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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