noam
noam

Reputation: 25

JPanel, BorderLayout works wrong

Well idc what i did but now everytime i start the program my screen just split into right side and left side, and i wanted them to merge and just put the red in the east side of the screen and its just like.. split into 2 panels .. im trying to make a world editor for my lwjgl game and i want to make a panel, that render my game on the area with the red screen on it, but i just cant put it in the right place here is a picture - http://prntscr.com/85o1es as you can see for some reason there is 2 screen there, i colored the panel in gray and u can see the panel is only on the right side... the rendering of the display is fine, red background and a model of a black square if someone knows why my screen splits plz help.

public class Panel
{

    private static JFrame frame;
    private static JPanel panel;
    private static Canvas glCanvas = new Canvas();
    private JMenuBar mb = new JMenuBar();
    private static Loader loader;
    private static Renderer renderer;


    public static void gui()
    {
        panel = new JPanel();
        frame = new JFrame("TEST");
        frame.setVisible(true);
        frame.setSize(1280, 1024);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        panel.setBackground(Color.GRAY);
        frame.add(panel,BorderLayout.EAST);
    }

    public static void main(String[] args)
    {
        gui();
        setCanvas();
        DisplayManager.createDisplay();
        loader = new Loader();
        renderer = new Renderer();

        float[] vertices =
        { -0.5f, 0.5f, 0f, -0.5f, -0.5f, 0f, 0.5f, -0.5f, 0f,

        0.5f, -0.5f, 0f, 0.5f, 0.5f, 0f, -0.5f, 0.5f, 0f };

        RawModel model = loader.loadToVAO(vertices);

        while (!Display.isCloseRequested())
        {
            renderer.prepare();
            renderer.render(model);
            DisplayManager.updateDisplay();
        }

        DisplayManager.closeDisplay();

    }

    private static void setCanvas()
    {
        glCanvas.setIgnoreRepaint(true);
        glCanvas.setSize(720, 480);
        panel.add(glCanvas);
        try
        {
            Display.setParent(glCanvas);
        }
        catch (LWJGLException e)
        {
            e.printStackTrace();
        }
    }

}

Upvotes: 1

Views: 132

Answers (1)

Madhawa Priyashantha
Madhawa Priyashantha

Reputation: 9872

change this to

 frame.add(panel,BorderLayout.EAST);

this

frame.add(panel,BorderLayout.CENTER);

why did you set position to BorderLayout.EAST?. set it to center .

what you see as split panel in left side is your jframe .because of you have set border-layout constrain to east your panel has positioned at the right side . if you not sure put

frame.getContentPane().setBackground(Color.green);

and you will see it's the frame.


edit.......

according to your comments you want to position your canvas at right bottom

so add panel to East as you already done

 frame.add(panel,BorderLayout.EAST);

set panel layout to border layout

panel.setLayout(new BorderLayout());

and add canvas to south of the panel

panel.add(glCanvas,BorderLayout.SOUTH);

Upvotes: 1

Related Questions