0

I am trying to make 3 panels re-size over each other I wrote the code for it. it should work. However, it did not. I am making 3 JPanel components, adding them to two split panes the first split pane holds The middle panel, and the Right panel. The second split pane holds the same middle panel, and the left panel, so the middle panel is in both split panes.

If you can help me with tackling this issue, I would be very grateful.

public class FinalProjectTestCase1 {

public static void main(String[] args)
{
    Frame frame = new Frame();
    frame.pack();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
}
}
class Frame extends JFrame 
{

JPanel LeftPanel;
JPanel MiddlePanel;
JPanel RightPanel;

Frame()
{
    this.setLayout(new BorderLayout());
    this.setPreferredSize(new Dimension(700,700));

    MiddlePanel= new JPanel();
    MiddlePanel.setLayout(new GridLayout());

    RightPanel= new JPanel();
    RightPanel.setLayout(new GridLayout());
    RightPanel.setPreferredSize(new Dimension(250,700));

    LeftPanel= new JPanel();
    LeftPanel.setLayout(new GridLayout());
    LeftPanel.setPreferredSize(new Dimension(250,700));

    JButton MiddlePanelb= new JButton("MiddlePanel");
    MiddlePanel.add(MiddlePanelb);

    JButton leftPanelb= new JButton("leftPanelb");
    LeftPanel.add(leftPanelb);

    JButton RightPanelb= new JButton("RightPanelb");
    RightPanel.add(RightPanelb);

    JSplitPane RightSplitPane= new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,(MiddlePanel),(RightPanel));
    JSplitPane LeftSplitPane= new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,(LeftPanel),(MiddlePanel));

    this.add(MiddlePanel);
    this.add(RightSplitPane,BorderLayout.EAST);
    this.add(LeftSplitPane,BorderLayout.WEST);
}
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 2
    `so the middle panel is in both split panes.` - a component can only have a single parent so it can't be in both split panes. You need to separate panels. – camickr May 03 '16 at 04:30
  • 2
    Don't call your class Frame. That is an AWT component so the class name is confusing. The name should be more descriptive. Also variable names should NOT start with an upper case character. Follow Java conventions. – camickr May 03 '16 at 04:52
  • 1
    1) A single blank line of white space in source code is all that is *ever* needed. Blank lines after `{` or before `}` are also typically redundant. 2) See [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/q/7229226/418556) (Yes.) 3) To use code formatting for code and code snippets, structured documents like HTML/XML or input/output, select the text and click the `{}` button at the top of the message posting/editing form. – Andrew Thompson May 03 '16 at 05:06
  • 1
    I'm sorry for both of you. I need to work on my naming conventions and write code appropriately. I will consider your words in my work from now on. – Ismael Alsabea May 03 '16 at 06:02
  • *"I'm sorry for both of you."* No need for apologies, not when you offer something better! *".. I need to work on my naming conventions and write code appropriately. I will consider your words in my work from now on."* That's what I wanted to hear, and I suspect @camickr feels the same as well. – Andrew Thompson May 03 '16 at 09:01
  • Tip on the nomenclature, a quick guide: `EachWordUpperCaseClass`, `firstWordLowerCaseMethod()`, `firstWordLowerCaseAttribute` unless it is an `UPPER_CASE_CONSTANT` – Andrew Thompson May 03 '16 at 09:03
  • Andrew Thompson Thanks for your notes. – Ismael Alsabea May 03 '16 at 20:28

0 Answers0