Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>GroupLayout</code> is a constraints-based layout. The base principle is to determine positionning constraints between the components, on the x and y axis independently.</p> <p>There are only two constraints : either the components are in sequence, or they are in parallel.</p> <p>In your case, your layout is simple :</p> <ul> <li>on the x axis, there are all the labels in parallel, and the all the textfields in parallel.</li> <li>on the y axis, there are groups of [label and then textfield], all in parallel</li> </ul> <p>The code for that is the following :</p> <pre><code>import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingUtilities; import javax.swing.UIManager; public class Progress extends JPanel { private JLabel ClientIP; private JTextField ip; private JLabel ClientPassword; private JTextField pass; private JLabel Videoname; private JTextField vname; private JLabel perccomplete; private JTextField percent; private JLabel PacketsSent; private JTextField pacsent; private JLabel Connectiontype; private JTextField conntype; private JLabel noofvideossent; private JTextField videosend; public Progress() { ClientIP = new JLabel("Client's IP:"); ClientPassword = new JLabel("Clients Password:"); Videoname = new JLabel("Video being Transfered:"); perccomplete = new JLabel("% of transfer Complete:"); PacketsSent = new JLabel("No of Packets sent:"); Connectiontype = new JLabel("Connection Type:"); noofvideossent = new JLabel("No of Videos Sent:"); ip = new JTextField(); pass = new JTextField(); vname = new JTextField(); percent = new JTextField(); pacsent = new JTextField(); conntype = new JTextField(); videosend = new JTextField(); ip.setColumns(20); pass.setColumns(20); vname.setColumns(20); percent.setColumns(20); pacsent.setColumns(20); conntype.setColumns(20); videosend.setColumns(20); //Tell accessibility tools about label/textfield pairs. ClientIP.setLabelFor(ip); ClientPassword.setLabelFor(pass); Videoname.setLabelFor(vname); perccomplete.setLabelFor(percent); PacketsSent.setLabelFor(pacsent); Connectiontype.setLabelFor(conntype); noofvideossent.setLabelFor(videosend); GroupLayout layout = new GroupLayout(this); setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup( layout.createSequentialGroup() .addGroup(layout.createParallelGroup(Alignment.LEADING) .addComponent(ClientIP) .addComponent(ClientPassword) .addComponent(Videoname) .addComponent(perccomplete) .addComponent(PacketsSent) .addComponent(Connectiontype) .addComponent(noofvideossent)) .addGroup(layout.createParallelGroup(Alignment.LEADING) .addComponent(ip) .addComponent(pass) .addComponent(vname) .addComponent(percent) .addComponent(pacsent) .addComponent(conntype) .addComponent(videosend))); layout.setVerticalGroup( layout.createSequentialGroup() .addGroup(layout.createParallelGroup(Alignment.BASELINE) .addComponent(ClientIP) .addComponent(ip)) .addGroup(layout.createParallelGroup(Alignment.BASELINE) .addComponent(ClientPassword) .addComponent(pass)) .addGroup(layout.createParallelGroup(Alignment.BASELINE) .addComponent(Videoname) .addComponent(vname)) .addGroup(layout.createParallelGroup(Alignment.BASELINE) .addComponent(perccomplete) .addComponent(percent)) .addGroup(layout.createParallelGroup(Alignment.BASELINE) .addComponent(PacketsSent) .addComponent(pacsent)) .addGroup(layout.createParallelGroup(Alignment.BASELINE) .addComponent(Connectiontype) .addComponent(conntype)) .addGroup(layout.createParallelGroup(Alignment.BASELINE) .addComponent(noofvideossent) .addComponent(videosend))); } public static void main(String[] args) throws Exception { SwingUtilities.invokeLater(new Runnable() { public void run() { UIManager.put("swing.boldMetal", Boolean.FALSE); JFrame f = new JFrame("test frame"); f.setContentPane(new Progress()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle("Find"); f.pack(); f.setVisible(true); } }); } } </code></pre> <p>A <code>GroupLayout</code> is relatively easy to understand, when the code is properly indented. I replaced the <code>Alignement.LEADING</code> by <code>Alignement.BASELINE</code>, in order to align on the baseline (the text of the labels and of the textfields are on the same line).</p>
    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.
    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