Reworked window size handling

Window is now resized properly at all times to embed the current frame purrfectly
This commit is contained in:
Bokros Bálint 2016-05-14 02:51:34 +02:00 committed by Kjistóf
parent 4f11f60b50
commit 80ff3e4383

View File

@ -36,20 +36,21 @@ public class ApplicationFrame implements Runnable
} }
jframe.add(gamepanel); jframe.add(gamepanel);
jframe.revalidate(); jframe.pack();
//jframe.revalidate(); //TODO check if needed
} }
} }
public void init(){ public void init(){
jframe = new JFrame(); jframe = new JFrame();
jframe.setFocusable(true); jframe.setFocusable(true);
jframe.setMinimumSize(new Dimension(menuDimension));
jframe.setLocationRelativeTo(null); jframe.setLocationRelativeTo(null);
jframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); jframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
initMapselector(); initMapselector();
jframe.add(mapselectorpanel); jframe.add(mapselectorpanel);
jframe.pack();
} }
public void backToMapSelection() { public void backToMapSelection() {
@ -57,7 +58,6 @@ public class ApplicationFrame implements Runnable
jframe.removeKeyListener(keyHandler); jframe.removeKeyListener(keyHandler);
initMapselector(); initMapselector();
jframe.add(mapselectorpanel); jframe.add(mapselectorpanel);
jframe.setMinimumSize(menuDimension);
jframe.pack(); jframe.pack();
jframe.revalidate(); jframe.revalidate();
} }
@ -81,6 +81,7 @@ public class ApplicationFrame implements Runnable
Control.ioErrorMessage(); Control.ioErrorMessage();
} }
} }
}; };
DefaultListModel<File> dungeonslist = new DefaultListModel<>(); DefaultListModel<File> dungeonslist = new DefaultListModel<>();
@ -99,6 +100,9 @@ public class ApplicationFrame implements Runnable
filelist.addMouseListener(new ListMouseHandler()); filelist.addMouseListener(new ListMouseHandler());
filelist.setMaximumSize(new Dimension(400, 80)); filelist.setMaximumSize(new Dimension(400, 80));
mapselectorpanel.setMinimumSize(menuDimension);
mapselectorpanel.setPreferredSize(menuDimension);
mapselectorpanel.setLayout(new BorderLayout()); mapselectorpanel.setLayout(new BorderLayout());
mapselectorpanel.addMouseListener(new MouseAdapter() { mapselectorpanel.addMouseListener(new MouseAdapter() {
@Override @Override
@ -115,11 +119,11 @@ public class ApplicationFrame implements Runnable
private void setGameParams(File dungeonFile) throws IOException { private void setGameParams(File dungeonFile) throws IOException {
gamepanel = new Display(); gamepanel = new Display();
jframe.setMinimumSize(gamepanel.getDimension());
jframe.pack();
jframe.addKeyListener(keyHandler);
Game.instance.setDisplay(gamepanel); Game.instance.setDisplay(gamepanel);
Game.instance.setDungeon(new Dungeon()); Game.instance.setDungeon(new Dungeon());
Game.instance.startGame(dungeonFile); Game.instance.startGame(dungeonFile);
jframe.addKeyListener(keyHandler);
} }
} }