What I am currently trying to make are 3 panels in a frame that is laid out via GridLayout(), and each of the 3 panels would have their own panels within them that would be containing text. The top-most panel would only contain a single line (a fake email address), while the panel below it would contain the contents of an email. However, when I try setting senderPanel (the panel within the other panel), the panel size does not change and stays zero.
` private void showLastJFrame(WindowAdapter windowAdapter){
JFrame frame3 = new JFrame();
frame3.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // We don’t want to exit the entire program when frame 2 is closed
frame3.setLayout(new GridLayout(1,3));
frame3.setSize(1600, 900);
frame3.addWindowListener(windowAdapter);
frame3.setVisible(true);
JPanel panel1 = new JPanel();
panel1.setSize(new Dimension(frame3.getWidth()/3,900));
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
// Set bounds and background color
panel1.setBackground(null);
panel2.setBackground(new Color(100,255,100));
panel3.setBackground(new Color(100,100,255));
String[] test = makeEmail.getEmail();
System.out.println(test[1]);
// Add labels to panels
JPanel senderPanel = new JPanel();
JLabel senderLabel = new JLabel(test[1]);
senderPanel.setBackground(Color.ORANGE);
senderPanel.setOpaque(true);
senderPanel.setSize(new Dimension(panel1.getWidth(),100));
System.out.println(senderPanel.getSize());
panel1.add(senderPanel);
// senderPanel.add(senderLabel);
System.out.println(panel1.getWidth()+ "" + panel1.getHeight());
// JPanel bodyPanel = new JPanel();
//JLabel bodyLabel = new JLabel(test[2]);
//bodyPanel.add(bodyLabel);
// panel1.add(bodyLabel);`
I’ve already tried making a grid layout within each panel so that the subpanel (senderPanel) would appear, which worked, however I can’t readjust their size. I have also already used setSize() on panel1 (the main panel) to try and give the subpanels reference dimensions so I could fit them. Additionally I have tried using a FlowLayout() for senderPanel, but that doesn’t resize it either.
Tibasco Sauce is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.