I am creating a GUI with a graphics panel, a command panel and a Command List panel. I've got the command panel where I want it at the bottom of the frame using BorderLayout South but my side panel is just tiny and unreadable.
Ill provide a picture of what I want my frame to look like at the end:
What I currently have:
Could anyone explain why the TitledBorder panel is so small?
My code is below:
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class PenDriver {
public static void main(String[] args) {
JFrame frame = new JFrame("Pen Simulator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 400);
penPanel panel = new penPanel();
frame.add(panel);
frame.setVisible(true);
}
}
AND
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
public class penPanel extends JPanel {
private JTextField userCommand;
private JLabel instruction1;
private JButton instruct, clear;
private JLabel cmd1;
public penPanel() {
setLayout(new BorderLayout());
// CREATE THE COMMAND PANEL///////
// Set Layout
JPanel command = new JPanel();
command.setLayout(new BoxLayout(command, BoxLayout.LINE_AXIS));
// Create Label and add to panel
instruction1 = new JLabel("Enter Command:");
// Create Buttons
instruct = new JButton("Execute");
clear = new JButton("Clear Graphics");
// Create Text Field to panel
userCommand = new JTextField(10);
command.add(instruction1);
command.add(Box.createRigidArea(new Dimension(4, 0)));
command.add(userCommand);
command.add(Box.createRigidArea(new Dimension(2, 0)));
command.add(instruct);
command.add(Box.createRigidArea(new Dimension(2, 0)));
command.add(clear);
// COMMAND PANEL FINISHED////////
// CREATE THE COMMAND LIST PANEL//////////
JPanel cmdList = new JPanel();
cmdList.setBorder(BorderFactory.createTitledBorder("Command List:"));
cmdList.setLayout(new BoxLayout(cmdList, BoxLayout.PAGE_AXIS));
cmd1 = new JLabel("UP = up");
cmdList.setSize(new Dimension(50, 400));
cmdList.add(cmd1);
add(command, BorderLayout.SOUTH);
add(cmdList, BorderLayout.EAST);
}
}
Thank you!
EDIT: After some tinkering to this code:
cmdList.setPreferredSize(new Dimension(120, 800));
cmdList.add(cmd1);
add(command, BorderLayout.SOUTH);
command.add(Box.createRigidArea(new Dimension(120, 0)));
add(cmdList, BorderLayout.EAST);
Still not quite what im going for and not sure if it's what I am supposed to do. Should I be altering the driver file rather than the JPanels directly?
Notice how there is still a gap to the right of the "Clear Graphics" Button. Any way to get rid of that?