I have a problem I would like to program a menu for a game console in Java, I use several JPanel and I change with frame.setContentPane (newMenu); between the JPanel now I would like that if I enlarge the JFrame that the JPanel enlarges so that the JPanel in the resolution 800x600 remains but the JFrame is for example in the resolution 1920x1080. I want to have it like RetroGames have black stripes left and right and no black stripes at the top and bottom.
Code: JFrame
frame = new JFrame(CGC_NAME + " [Version: " + CGC_VERSION + "]");
frame.setSize(DISPLAY_WIDTH, DISPLAY_HEIGHT);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);
frame.setLayout(null);
displayPanel = new JPanel();
displayPanel.setBounds(0,0, Menu.MENU_WIDTH, Menu.MENU_HEIGHT);
frame.add(displayPanel);
Menu.changeMenu(null, Menu.homeMenu);
frame.setFocusable(true);
frame.requestFocus();
frame.addKeyListener(new Keyboard());
Code JPanel
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
renderMenu(g);
repaint();
}
protected abstract void runMenu();
protected abstract void renderMenu(Graphics g);
public static void changeMenu(Menu oldMenu, Menu newMenu) {
//CGC.frame.setContentPane(newMenu);
if (oldMenu != null) {
CGC.displayPanel.remove(oldMenu);
}
CGC.displayPanel.setLayout(new BorderLayout());
CGC.displayPanel.add(newMenu, BorderLayout.CENTER);
CGC.frame.revalidate();
CGC.frame.repaint();
newMenu.runMenu();
}
Can someone help me? Cortablo