0

Note: I'm new to LayoutManagers or GUIs in general.

I've been working for this for hours and search for any reference and solutions and I still don't know why my components are overlapping. My GUI should look somewhat like this see correct output here

when I run my program and maximize itsee my output here

The two components are found in two different methods the code for toolbar is this

  void the Tool(){
    JPanel panel=new JPanel(new FlowLayout(FlowLayout.LEFT));
    JToolBar toolBar = new JToolBar(JToolBar.VERTICAL);

    //4 buttons
    //adding buttons to toolBar 

    panel.add(toolBar);
    panel.setSize(300,300);
    add(panel,BorderLayout.NORTH);
    validate();
  }

Meanwhile my code for the panel goes something like this

 void thePanel(){

    JPanel panel=new JPanel(new FlowLayout(FlowLayout.CENTER));

    JLabel label=new JLabel(new ImageIcon("panel.jpg"));
    panel.add(label);
    add(panel,BorderLayout.NORTH);
    validate();
  }
TinTin
  • 1
  • 2
  • 1
    1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) One way to get image(s) for an example is to hot link to images seen in [this Q&A](http://stackoverflow.com/q/19209650/418556). 3) `panel.setSize(300,300);` A layout manager is more likely to honour the preferred size, than the size, but see [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/q/7229226/418556) (Yes.) – Andrew Thompson Nov 16 '16 at 14:35
  • The code `add(panel,BorderLayout.NORTH);` appears in both methods. If they are added components to the same container with border layout, one will appear over the top of the other. That is possibly the problem here, but for more than 'possibly', post that MCVE. – Andrew Thompson Nov 16 '16 at 14:40
  • I fixed it now. Thank you very much! – TinTin Nov 16 '16 at 14:55
  • Now you might write an answer below (not as a comment, but scroll down further and put is *as an answer*), or simply delete the question using the link below the question tags. – Andrew Thompson Nov 16 '16 at 16:50

0 Answers0