hii every one,
following is my code which displays 4 panel
one is at NORTH,....WEST , SOUTH
i want to display am image at EAST at container
how is it possible?
public class ImageProcessor extends JApplet {
JPanel panel1,panel2,panel3,panel4,panel5;
JTextField nameTxt,addTxt,phoneTxt,emailTxt;
JButton capture,download,cancle,sendEmail;
JLabel head,name,add,phone,email;
//function to align components using gridBagLayOut..
private GridBagConstraints getConstraints(int gridx, int gridy,int gridwidth, int gridheight, int anchor)
{
GridBagConstraints c =new GridBagConstraints();
c.insets = new Insets(10,10,10,10);
c.ipadx = 0;
c.ipady = 0;
c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = gridwidth;
c.gridheight = gridheight;
c.anchor = anchor;
return c;
}
//ends here...
public void init() {
panel1 = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();
panel4 = new JPanel();
panel5 = new JPanel();
nameTxt = new JTextField(20);
addTxt = new JTextField(20);
phoneTxt = new JTextField(20);
emailTxt = new JTextField(20);
capture = new JButton("capture");
download = new JButton("download");
sendEmail = new JButton("sendEmail");
head = new JLabel("BUSINESS CARD READER");
name = new JLabel("NAME:");
add = new JLabel("ADDRESS:");
phone = new JLabel("PHONE:");
email = new JLabel("EMAIL:");
Container myPane = getContentPane();
myPane.setLayout(new BorderLayout());
panel1.setLayout(new BorderLayout());
panel2.setLayout(new GridBagLayout());
panel2.add(head,getConstraints(0,0,1,1,GridBagConstraints.CENTER));
panel3.setLayout(new FlowLayout());
panel3.add(capture);
panel3.add(download);
panel3.add(sendEmail);
panel4.setLayout(new GridBagLayout());
panel4.add(name,getConstraints(0,0,1,1,GridBagConstraints.CENTER));
panel4.add(nameTxt,getConstraints(1,0,1,1,GridBagConstraints.CENTER));
panel4.add(add,getConstraints(0,1,1,1,GridBagConstraints.CENTER));
panel4.add(addTxt,getConstraints(1,1,1,1,GridBagConstraints.CENTER));
panel4.add(phone,getConstraints(0,2,1,1,GridBagConstraints.CENTER));
panel4.add(phoneTxt,getConstraints(1,2,1,1,GridBagConstraints.CENTER));
panel4.add(email,getConstraints(0,3,1,1,GridBagConstraints.CENTER));
panel4.add(emailTxt,getConstraints(1,3,1,1,GridBagConstraints.CENTER));
panel1.add(panel2,BorderLayout.NORTH);
panel1.add(panel3,BorderLayout.SOUTH);
panel1.add(panel4,BorderLayout.WEST);
panel1.add(panel5,BorderLayout.EAST);
setSize(500,500);
myPane.add(panel1,BorderLayout.CENTER);
}
public void start(){
this.setSize(800,500);
}
}
Create a JLabel without text ("") and use setIcon to set the image to be displayed.
Here is an example.
Add the picture on a JButton or JLabel to your panel5:
JButton buttonForPicture = new JButton();
buttonForPicture.setBorder(new EmptyBorder(0, 0, 0, 0));
buttonForPicture.setOpaque(false);
buttonForPicture.setIcon(new ImageIcon(imageFilePath));
panel5.add(buttonForPicture);
Related
I have a JPanel with a textfield (textPanel). I added the textPanel for some reasons to another panel (contentPanel) and that to the JFrame. I have added a MouseListener to the textPanel, so that I can drag it around. The new Position is set by the methodcall setLocation (...)
Everytime I start editing the textfield, the textpanel jumps back from its actual location to the center of the JFrame. – Why? What do I have to change?
public void run() {
area1 = new JTextArea();
area1.setText("Hello!");
GridBagLayout layout = new GridBagLayout();
GridBagConstraints cc = new GridBagConstraints();
cc.fill = GridBagConstraints.NONE;
textPanel = new JPanel(layout);
cc.anchor = GridBagConstraints.PAGE_START;
cc.gridx = 0;
textPanel.add(area1, cc);
JPanel contentPanel = new JPanel(new GridBagLayout());
cc = new GridBagConstraints();
cc.anchor = GridBagConstraints.FIRST_LINE_START;
cc.gridx = 0;
cc.gridy = 0;
cc.weightx = 1;
cc.weighty = 1;
MyMouseAdapter mh = new MyMouseAdapter();
textPanel.addMouseListener(mh);
textPanel.addMouseMotionListener(mh);
contentPanel.add(textPanel, cc);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.add(contentPanel);
frame.setSize(800, 600);
frame.setVisible(true);
}
I am trying to create a GUI that runs a guessing game, but have gotten stuck using GridBagLayout. The problem is with the sizing of the JPanel within my JFrame.
I have already written a similar program that works just fine, and do not understand why one works and the other does not.
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.*;
public class GuessGame {
private static JTextField inputBox;
GuessGame(){}
public static void main(String[] args) {
createWindow();
}
private static void createWindow() {
JFrame frame = new JFrame("GuessingGame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
createUI(frame);
frame.setSize(600, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private static void createUI(JFrame frame) {
JPanel panel = new JPanel();
GridBagLayout layout = new GridBagLayout();
panel.setLayout(layout);
GuessGame guessingGame = new GuessGame();
GridBagConstraints gbc = new GridBagConstraints();
inputBox = new JTextField(10);
inputBox.setEditable(false);
JLabel title = new JLabel("FUN FUN Guessing Game");
JLabel entryBoxLabel = new JLabel("Entry Box: ");
JLabel statsOptions = new JLabel("Statistics Options");
JLabel message = new JLabel("HAVE FUN!!!");
JButton startGame = new JButton("START");
JButton clearDisplay = new JButton("CLEAR");
JButton displayStats = new JButton("STATS");
JCheckBox bestTime = new JCheckBox("Best Time");
JCheckBox bestPlays = new JCheckBox("Best # of Plays");
JCheckBox bestPlayer = new JCheckBox("Best Player");
JTextArea displayArea = new JTextArea(300, 300);
JScrollPane scrollWrap = new JScrollPane(displayArea);
gbc.anchor = GridBagConstraints.ABOVE_BASELINE;
gbc.gridx = 0; gbc.gridy = 0; panel.add(title, gbc);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 0; gbc.gridy = 1; panel.add(startGame, gbc);
gbc.fill = GridBagConstraints.WEST;
gbc.gridx = 1; gbc.gridy = 1; panel.add(entryBoxLabel, gbc);
gbc.fill = GridBagConstraints.LINE_END;
gbc.gridx = 1; gbc.gridy = 1; panel.add(inputBox, gbc);
gbc.fill = GridBagConstraints.NONE;
gbc.gridx = 0; gbc.gridy = 2; panel.add(displayArea, gbc);
gbc.gridx = 1; gbc.gridy = 2; panel.add(scrollWrap, gbc);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 0; gbc.gridy = 3; panel.add(clearDisplay, gbc);
gbc.anchor = GridBagConstraints.NORTH;
gbc.gridx = 1; gbc.gridy = 3; panel.add(statsOptions, gbc);
gbc.anchor = GridBagConstraints.SOUTHWEST;
gbc.gridx = 1; gbc.gridy = 3; panel.add(bestTime, gbc);
gbc.anchor = GridBagConstraints.SOUTH;
gbc.gridx = 1; gbc.gridy = 3; panel.add(bestPlays, gbc);
gbc.anchor = GridBagConstraints.SOUTHEAST;
gbc.gridx = 1; gbc.gridy = 3; panel.add(bestPlayer, gbc);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridx = 0; gbc.gridy = 4; panel.add(displayStats, gbc);
gbc.gridx = 1; gbc.gridy = 4; panel.add(message, gbc);
frame.getContentPane().add(panel, BorderLayout.CENTER);
}
}
I was expecting something that looks like this:
!https://imgur.com/20HVSxR
But what I got was this:
!https://imgur.com/AnMJtt7
HALP
Instad of using GridBad, I prefer using BoxLayout. Here is my approach to your problem. This is the closest you can get to the image you posted using Swing.
import java.awt.*;
import javax.swing.*;
public class Test {
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
JFrame frame = new JFrame();
JPanel north = createNorthPanel();
JPanel center = createCenterPanel();
JPanel south = createSouthPanel();
frame.add(north, BorderLayout.NORTH);
frame.add(center, BorderLayout.CENTER);
frame.add(south, BorderLayout.SOUTH);
frame.setLocationByPlatform(true);
frame.pack();
frame.setVisible(true);
}
private static JPanel createNorthPanel() {
JPanel northPanel = new JPanel();
BoxLayout northPanelLayout = new BoxLayout(northPanel, BoxLayout.Y_AXIS);
northPanel.setLayout(northPanelLayout);
JPanel upperPanel = new JPanel();
JLabel funFunGuessingGameLabel = new JLabel("FUN FUN Guessing Game");
funFunGuessingGameLabel.setFont(funFunGuessingGameLabel.getFont().deriveFont(Font.ITALIC));
upperPanel.add(funFunGuessingGameLabel);
upperPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
JPanel lowerPanel = new JPanel();
BoxLayout lowerPanelLayout = new BoxLayout(lowerPanel, BoxLayout.X_AXIS);
lowerPanel.setLayout(lowerPanelLayout);
JButton startButton = new JButton("START");
startButton.setPreferredSize(new Dimension(175,(int)startButton.getPreferredSize().getHeight()));
JLabel entryBoxLabel = new JLabel("Entry Box: ");
JTextField entryBoxTextField = new JTextField();
lowerPanel.add(startButton);
lowerPanel.add(Box.createHorizontalStrut(10));
lowerPanel.add(entryBoxLabel);
lowerPanel.add(entryBoxTextField);
lowerPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
northPanel.add(upperPanel);
northPanel.add(lowerPanel);
return northPanel;
}
private static JPanel createCenterPanel() {
JPanel centerPanel = new JPanel();
BoxLayout centerPanelLayout = new BoxLayout(centerPanel, BoxLayout.Y_AXIS);
centerPanel.setLayout(centerPanelLayout);
JLabel l1 = new JLabel("Guesses and statistics are shown in this display as a scrollable list, e.g.: ");
JLabel l2 = new JLabel("(1,3,5)é(0,0)");
JLabel l3 = new JLabel("(2,4,6)é(0,0)");
JLabel l4 = new JLabel("(7,8,9)é(0,0)");
Box space = Box.createVerticalBox();
centerPanel.add(Box.createHorizontalStrut(10));
centerPanel.add(l1);
centerPanel.add(Box.createVerticalStrut(10));
centerPanel.add(l2);
centerPanel.add(Box.createVerticalStrut(5));
centerPanel.add(l3);
centerPanel.add(Box.createVerticalStrut(5));
centerPanel.add(l4);
centerPanel.add(Box.createVerticalStrut(40));
centerPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
return centerPanel;
}
private static JPanel createSouthPanel() {
JPanel southPanel = new JPanel();
BoxLayout southPanelLayout = new BoxLayout(southPanel, BoxLayout.Y_AXIS);
southPanel.setLayout(southPanelLayout);
JPanel upperPanel = new JPanel();
BoxLayout upperPanelLayout = new BoxLayout(upperPanel, BoxLayout.X_AXIS);
upperPanel.setLayout(upperPanelLayout);
JPanel clearButtonPanel = new JPanel(new BorderLayout(0, 0));
JButton clearButton = new JButton("CLEAR");
clearButton.setPreferredSize(new Dimension(175, (int) clearButton.getPreferredSize().getHeight()));
clearButtonPanel.add(clearButton);
JPanel innerPanel = new JPanel();
BoxLayout innerPanelLayout = new BoxLayout(innerPanel, BoxLayout.Y_AXIS);
innerPanel.setLayout(innerPanelLayout);
JPanel statisticsOptionsLabelPanel = new JPanel();
JLabel statisticsOptionsLabel = new JLabel("Statistics Options");
statisticsOptionsLabelPanel.add(statisticsOptionsLabel);
JPanel checkBoxPanel = new JPanel();
BoxLayout checkBoxPanelLayout = new BoxLayout(checkBoxPanel, BoxLayout.X_AXIS);
checkBoxPanel.setLayout(checkBoxPanelLayout);
JCheckBox bestTimeCheckBox = new JCheckBox("Best Time");
JCheckBox bestNumOfPlaysCheckBox = new JCheckBox("Best # of plays");
JCheckBox topPlayerCheckBox = new JCheckBox("Top Player");
checkBoxPanel.add(bestTimeCheckBox);
checkBoxPanel.add(bestNumOfPlaysCheckBox);
checkBoxPanel.add(topPlayerCheckBox);
innerPanel.add(statisticsOptionsLabelPanel);
upperPanel.add(Box.createVerticalGlue());
innerPanel.add(checkBoxPanel);
upperPanel.add(clearButtonPanel);
upperPanel.add(Box.createHorizontalStrut(14));
upperPanel.add(innerPanel);
upperPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
JPanel lowerPanel = new JPanel();
BoxLayout lowerPanelLayout = new BoxLayout(lowerPanel, BoxLayout.X_AXIS);
lowerPanel.setLayout(lowerPanelLayout);
JButton statsButton = new JButton("STATS");
statsButton.setPreferredSize(new Dimension(175,(int)statsButton.getPreferredSize().getHeight()));
JLabel haveFunLabel = new JLabel("Have Fun!!!");
lowerPanel.add(statsButton);
lowerPanel.add(Box.createHorizontalGlue());
lowerPanel.add(haveFunLabel);
lowerPanel.add(Box.createHorizontalGlue());
lowerPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
southPanel.add(upperPanel);
southPanel.add(lowerPanel);
return southPanel;
}
}
I am having trouble adding a scroll pane to a nested panel. Here is what I have:
public class board {
public static void addComponentsToPane(Container pane) {
pane.setLayout(new GridLayout(1, 0));
JPanel left = new JPanel();
pane.add(left);
left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS));
JPanel leftTop = new JPanel();
leftTop.setPreferredSize(new Dimension(266, 300));
leftTop.setBackground(Color.black);
left.add(leftTop);
JScrollPane scrollPane = new JScrollPane(leftTop); //problem is here
left.add(scrollPane);
JButton jb = new JButton();
jb.setPreferredSize(new Dimension(250,50));
leftTop.add(jb);
JButton jb1 = new JButton();
jb1.setPreferredSize(new Dimension(250,50));
leftTop.add(jb1);
JButton jb2 = new JButton();
jb2.setPreferredSize(new Dimension(250,50));
leftTop.add(jb2);
JButton jb3 = new JButton();
jb3.setPreferredSize(new Dimension(250,50));
leftTop.add(jb3);
JButton jb4 = new JButton();
jb4.setPreferredSize(new Dimension(250,50));
leftTop.add(jb4);
JButton jb5 = new JButton();
jb5.setPreferredSize(new Dimension(250,50));
leftTop.add(jb5);
JButton jb6 = new JButton();
jb6.setPreferredSize(new Dimension(250,50));
leftTop.add(jb6);
JPanel leftBottom = new JPanel();
leftBottom.setPreferredSize(new Dimension(266, 300));
leftBottom.setBackground(Color.red);
left.add(leftBottom);
JPanel middle = new JPanel();
pane.add(middle);
middle.setLayout(new BoxLayout(middle, BoxLayout.Y_AXIS));
JPanel middleTop = new JPanel();
middleTop.setPreferredSize(new Dimension(266, 200));
middleTop.setBackground(Color.green);
middle.add(middleTop);
JPanel middleBottom = new JPanel();
middleBottom.setPreferredSize(new Dimension(266, 400));
middleBottom.setBackground(Color.yellow);
middle.add(middleBottom);
JPanel right = new JPanel();
right.setPreferredSize(new Dimension(266, 600));
right.setBackground(Color.blue);
pane.add(right);
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("GridBagLayoutDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addComponentsToPane(frame.getContentPane());
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
createAndShowGUI();
}
});
}
}
I am just messing around with JPanels and I cannot seem to add scrolling to the left top pane. I think i initialized scrollPane right, but am I adding it to the wrong pane?
Your initial problem is here
leftTop.setPreferredSize(new Dimension(266, 300));
This is overriding what the layout manager (FlowLayout in this case) would otherwise provide to the JScrollPane in order for it to know how to manage the view (when to show the scrollbars for instance)
The next problem you will have is, FlowLayout won't do what you want it to. Instead you might want to use GridLayout or maybe GridBagLayout instead
JPanel leftTop = new JPanel(new GridBagLayout());
//leftTop.setPreferredSize(new Dimension(266, 300));
leftTop.setBackground(Color.black);
JScrollPane scrollPane = new JScrollPane(leftTop); //problem is here
left.add(scrollPane);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1;
gbc.insets = new Insets(5, 10, 5, 10);
JButton jb = new JButton();
jb.setPreferredSize(new Dimension(250, 50));
leftTop.add(jb, gbc);
JButton jb1 = new JButton();
jb1.setPreferredSize(new Dimension(250, 50));
leftTop.add(jb1, gbc);
JButton jb2 = new JButton();
jb2.setPreferredSize(new Dimension(250, 50));
leftTop.add(jb2, gbc);
JButton jb3 = new JButton();
jb3.setPreferredSize(new Dimension(250, 50));
leftTop.add(jb3, gbc);
JButton jb4 = new JButton();
jb4.setPreferredSize(new Dimension(250, 50));
leftTop.add(jb4, gbc);
JButton jb5 = new JButton();
jb5.setPreferredSize(new Dimension(250, 50));
leftTop.add(jb5, gbc);
JButton jb6 = new JButton();
jb6.setPreferredSize(new Dimension(250, 50));
leftTop.add(jb6, gbc);
Know, if that's not meeting your needs, you will need to create a custom component which implements Scrollable, which will allow you to specify PreferredScrollableViewportSize which will tell the JScrollPane what the preferred size of the viewable area should be, rather then using the preferredSize of the view
I am new to java swing, I wrote a startup program to formart text, but i am confused with the layout,
the result is below:
I want the combobox and the button are placed middle of the ctrlPanel, and the combobox should not be stretched
public class MainFrame extends JFrame {
private static final long serialVersionUID = 7553142908344084288L;
private static String[] formats = new String[] {
"JSON",
"XML",
"YAML"
};
public MainFrame() {
super("jValidator");
Panel mainPanel = new Panel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.X_AXIS));
setContentPane(mainPanel);
JTextArea fromTextArea = new JTextArea(20, 40);
JScrollPane fromTextAreaScrollPanel = new JScrollPane(fromTextArea);
fromTextAreaScrollPanel.setPreferredSize(new Dimension(300, 300));
fromTextAreaScrollPanel.setBorder(BorderFactory.createEmptyBorder(15, 5, 15, 5));
mainPanel.add(fromTextAreaScrollPanel);
JButton fmtButton = new JButton("Format >>");
JComboBox jComboBox = new JComboBox(formats);
jComboBox.setBorder(BorderFactory.createTitledBorder("Text Format"));
JPanel ctrPanel = new JPanel();
ctrPanel.setLayout(new BoxLayout(ctrPanel, BoxLayout.Y_AXIS));
ctrPanel.setAlignmentY(Component.CENTER_ALIGNMENT);
ctrPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
ctrPanel.add(jComboBox);
ctrPanel.add(Box.createRigidArea(new Dimension(50, 15)));
ctrPanel.add(fmtButton);
mainPanel.add(ctrPanel);
JTextArea toTextArea = new JTextArea(20, 40);
JScrollPane toTextAreaScrollPanel = new JScrollPane(toTextArea);
toTextAreaScrollPanel.setPreferredSize(new Dimension(300, 300));
toTextAreaScrollPanel.setBorder(BorderFactory.createEmptyBorder(15, 5, 15, 5));
mainPanel.add(toTextAreaScrollPanel);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public static void main(String[] args) {
new MainFrame();
}
}
You could use a GridBagLayout instead of a BoxLayout...
JPanel ctrPanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = GridBagConstraints.REMAINDER;
ctrPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
gbc.fill = GridBagConstraints.HORIZONTAL;
ctrPanel.add(jComboBox, gbc);
ctrPanel.add(Box.createRigidArea(new Dimension(50, 15)), gbc);
gbc.fill = GridBagConstraints.NONE;
ctrPanel.add(fmtButton, gbc);
Take a look at Laying Out Components Within a Container for more details
For that purposes I recommend you to use another LayoutManager, for example GridBagLayout change creation of ctrPanel like next :
JButton fmtButton = new JButton("Format >>");
JComboBox jComboBox = new JComboBox(formats);
jComboBox.setBorder(BorderFactory.createTitledBorder("Text Format"));
JPanel ctrPanel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx=0;
c.gridy=1;
ctrPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
ctrPanel.add(fmtButton,c);
c.gridy=0;
c.fill = GridBagConstraints.HORIZONTAL;
ctrPanel.add(jComboBox,c);
mainPanel.add(ctrPanel);
And it looks like:
I am new to GUI in java, and have been using this video to learn. When I run the program, the window is blank until I resize it.
public class GUIProgram extends JFrame
{
int screenWidth = 1000; //screenSize.width;
int screenHeight = 800; //screenSize.height;
public GUIProgram()
{
super("DATABASE");
setSize(screenWidth, screenHeight);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel p = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel(new GridBagLayout());
JButton b = new JButton("Button 1");
JButton c = new JButton("Button 2");
p.add(b);
p.add(c);
JCheckBox cb = new JCheckBox("Do you LOVE bacon?");
JCheckBox cb2 = new JCheckBox("Do you LOVE cheese?");
p2.add(cb);
p2.add(cb2);
JLabel label = new JLabel("This is a label");
JTextArea tb = new JTextArea("this is a test area");
JTextField textField = new JTextField("text field");
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(15,15,15,15);
gbc.gridx = 0;
gbc.gridy = 0;
p3.add(label, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
p3.add(tb, gbc);
gbc.gridx = 1;
gbc.gridy = 2;
p3.add(textField, gbc);
add(p, BorderLayout.SOUTH);
add(p3, BorderLayout.CENTER);
add(p2, BorderLayout.NORTH);
}
}
Thanks in advance to anyone who can lend me some advice!
Please let me know if there is some ambiguity in what I'm asking or how I explained myself.
Call setVisible() last, immediately after pack().
Tip:
setSize(screenWidth, screenHeight); Don't set the size of top level containers. Instead layout the content & call pack().