0

I have a class that extends JPanel.

public class SomethingClass extends JPanel implements ActionListener{

When I add this class (which extends JPanel) to a JFrame it covers the JFrames very think black line border on the south side and east side.

It looks messy as the JFrame border on the east side is still there. I would like to get the JFrame to have a border on its south and west edges but I am stumped.

This is an image of the GUI:

enter image description here

I create the JFrame in my main method like this:

    SomethingClass something = new SomethingClass();
    JFrame frame = new JFrame(something); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
    frame.getContentPane().add(new SomethingClass());
    frame.setSize(400, 200);
    frame.setResizable(false);
    frame.setVisible(true); 
6
  • You'll need to create a compilable example of this. Your question is so general, it is almost like you're saying. " A JFrame doesn't look nice on my computer." Maybe you could include an image, because a JFrame on my computer doesn't even have a border.
    – matt
    Commented Apr 21, 2020 at 5:11
  • Screenshot added
    – phebus
    Commented Apr 21, 2020 at 5:21
  • That helps, can you also add enough code to make something that compiles? Does just a JFrame + JLabel draw correctly, or is it specific to your JPanel implementation?
    – matt
    Commented Apr 21, 2020 at 5:53
  • 1) For better help sooner, edit to add a minimal reproducible example or Short, Self Contained, Correct Example. 2) Provide ASCII art or a simple drawing of the intended layout of the GUI at minimum size, and if resizable, with more width and height - to show how the extra space should be used. 3) Most of the code seen above is about centering the frame on-screen. That can a) be done in a single line of code, and.. b) is irrelevant to the layout problem. Remove it. 4) frame.setResizable(false); should be done before a frame is sized, as it removes some of the frame 'chrome'. Commented Apr 21, 2020 at 8:36
  • Thanks Andrew! if i remove frame.setResizable(false) the border on the right hand side comes back and the JFrame looks neat. However putting it ahead of frame.setSize(400,200) changed nothing.
    – phebus
    Commented Apr 22, 2020 at 6:55

0