Note that there are some explanatory texts on larger screens.

plurals
  1. POAligning panels with GridBagLayout
    primarykey
    data
    text
    <p>I'm not exactly new to java (I've been using it for a year now) but this is my first go at swing. I'm trying to make a very simple chat client to learn both socket and swing at once. My question is "What must I do to align my panels correctly?". I've tried a lot of things (Though I don't have it in my code). Usually I work something like this out on my own, but I'm to the point I need to ask for help. Do I need to change the wieghtx, weighty? What I want the client to look like is something like this. </p> <p><img src="https://i.stack.imgur.com/ATtli.png" alt="enter image description here"></p> <p>This is what it currently looks like.</p> <p><img src="https://i.stack.imgur.com/WNtEl.png" alt="enter image description here"></p> <p>Here is my code.</p> <pre><code>package com.client.core; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Window extends JFrame{ private int screenWidth = 800; private int screenHeight = 600; public Window(){ //Initial Setup super("NAMEHERE - Chat Client Alpha v0.0.1"); setResizable(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(screenWidth,screenHeight); GridBagConstraints c = new GridBagConstraints(); //Main Panel JPanel window = new JPanel(); window.setLayout(new GridBagLayout()); window.setBackground(Color.black); //Panels JPanel display = new JPanel(); JPanel chat = new JPanel(); chat.setLayout(new GridBagLayout()); JPanel users = new JPanel(); display.setBackground(Color.blue); c.gridx = 0; c.gridy = 0; c.insets= new Insets(5,5,5,5); window.add(display, c); chat.setBackground(Color.red); c.gridx = 0; c.gridy = 3; c.gridheight = 2; c.gridwidth = 1; c.insets= new Insets(5,5,5,5); window.add(chat, c); users.setBackground(Color.green); c.gridx = 2; c.gridy = 0; c.insets= new Insets(5,5,5,5); window.add(users, c); //Buttons //Text fields JTextArea text = new JTextArea("DEREADFADSFEWFASDFSADFASDF"); c.gridx = 0; c.gridy = 0; chat.add(text); JTextField input = new JTextField("type here to chat", 50); c.gridx = 0; c.gridy = 1; c.insets= new Insets(5,5,5,5); chat.add(input); add(window); } static class ActLis implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { // 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.
 

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