Note that there are some explanatory texts on larger screens.

plurals
  1. POjava- Swing- Weird GroupLayout
    primarykey
    data
    text
    <p>This is my code:</p> <pre><code>package darkorbit; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.util.concurrent.TimeUnit; import javax.swing.GroupLayout; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.WindowConstants; public class GuiPreparation extends JFrame{ private JCheckBox cbbt = new JCheckBox("Wait"); private JTextField tfbt = new JTextField(5); private JLabel mbt = new JLabel("-"); private JTextField tfbt1 = new JTextField(5); private JLabel lbt = new JLabel("miliseconds after collecting a box."); private JCheckBox cbr = new JCheckBox("Rest"); private JTextField tfr = new JTextField(5); private JLabel mr = new JLabel("-"); private JTextField tfr1 = new JTextField(5); private JLabel lr = new JLabel("seconds every"); private JTextField tfr2 = new JTextField(5); private JLabel mr1 = new JLabel("-"); private JTextField tfr3 = new JTextField(5); private JLabel lr1 = new JLabel("minutes."); private JButton startBotting = new JButton("Start Botting"); private int controlWidth = 500; private int controlHeight = 600; GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); int screenWidth = gd.getDisplayMode().getWidth(); int screenHeight = gd.getDisplayMode().getHeight(); private GuiPreparation(){ setVisible(true); setResizable(false); setDefaultCloseOperation(EXIT_ON_CLOSE); setBounds(screenWidth / 2 - controlWidth / 2, screenHeight / 2 - controlHeight / 2, controlWidth, controlHeight); eventStartBotting startBottingEvent = new eventStartBotting(); startBotting.addActionListener(startBottingEvent); //startBotting.setBounds(controlWidth / 2 - 100 / 2, controlHeight - 70, 100, 30); //Layout add(startBotting); add(cbbt); add(tfbt); add(mbt); add(tfbt1); add(lbt); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup( layout.createSequentialGroup() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(cbbt)) .addComponent(tfbt) .addComponent(mbt) .addComponent(tfbt1) .addComponent(lbt) ); layout.setVerticalGroup( layout.createSequentialGroup() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(cbbt) .addComponent(tfbt) .addComponent(mbt) .addComponent(tfbt1) .addComponent(lbt)) ); layout.linkSize(SwingConstants.VERTICAL, tfbt); layout.linkSize(SwingConstants.VERTICAL, tfbt1); //Layout1 add(cbr); add(tfr); add(mr); add(tfr1); add(lr); add(tfr2); add(mr1); add(tfr3); add(lr1); GroupLayout layout1 = new GroupLayout(getContentPane()); getContentPane().setLayout(layout1); layout1.setAutoCreateGaps(true); layout1.setAutoCreateContainerGaps(true); layout1.setHorizontalGroup( layout1.createSequentialGroup() .addGroup(layout1.createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(cbr)) .addComponent(tfr) .addComponent(mr) .addComponent(tfr1) .addComponent(lr) .addComponent(tfr2) .addComponent(mr1) .addComponent(tfr3) .addComponent(lr1) ); layout1.setVerticalGroup( layout1.createSequentialGroup() .addGap(50) .addGroup(layout1.createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(cbr) .addComponent(tfr) .addComponent(mr) .addComponent(tfr1) .addComponent(lr) .addComponent(tfr2) .addComponent(mr1) .addComponent(tfr3) .addComponent(lr1)) ); layout1.linkSize(SwingConstants.VERTICAL, tfr); layout1.linkSize(SwingConstants.VERTICAL, tfr1); layout1.linkSize(SwingConstants.VERTICAL, tfr2); layout1.linkSize(SwingConstants.VERTICAL, tfr3); } public class eventStartBotting implements ActionListener { public void actionPerformed(ActionEvent startBottingActionEvent) { System.out.println("Event Start Botting"); startBotting.setEnabled(false); GuiBotting.openGui(); setVisible(false); dispose(); } } public static void openGui() { GuiPreparation mainGUI = new GuiPreparation(); mainGUI.setVisible(true); } } </code></pre> <p>So when I run the gui (<code>openGui()</code>), it runs smoothly, i get what i want: <img src="https://i.stack.imgur.com/9pBdh.png" alt="What I want"></p> <p>But then I change(for example) setReziseable(true) instead of false and run it I get this: <img src="https://i.stack.imgur.com/YPVQ3.png" alt="What I don&#39;t want"></p> <p>When I set it back i get the same.</p> <p>And to get the gui I want again, I have to press Ctrl+z untill it is set back to it's original.</p> <p>Sometimes I get the weird one even when i havent changed anything</p> <p>These are examples, y get this weird things by changing anything, and get different results even when the code is exactly the same.</p> <p>Is it the use of 2 layouts? is it that it doesn't shut down correctly? It if matters, I use Eclipse.</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. 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