I'm a beginner with Graphic User Interface and I'm working on a a game project. The class I'm writing GameMenu is a JComponent and the purpose of it is that within my game I will be making a GameMenu object and it will be handling the loading of the game, just a visual representation. However, instead of using a layout manager I decided to do the GameMenu loading with absolute positioning in which I have a ProgressBar and a Frame together. I set the size of the Frame to be 500 by 500 and the ProgressBar also to be the dimension of 500 by 500, what I have thought the result to be is that the Frame and ProgressBar should be the same size, but when I run the code the ProgressBar appears to be a little bigger than my Frame. Thus I have to resize the Frame in order to see the entire ProgressBar. I don't know whether my code is wrong or is it that ProgressBar by nature appears to be a little bigger in size if you positioning it by yourself. How do I set the Frame and ProgressBar to be the same size without resizing?
public class GameMenu extends JComponent
{
private JProgressBar loadbar;
private JFrame gui;
public GameMenu()
{
loadbar=new JProgressBar();
gui=new JFrame();
}
public void init()
{
gui.setLayout(null);
loadbar.setStringPainted(true);
gui.setBounds(0,0,500,500);
loadbar.setBounds(0,0,500,500);
loadbar.setVisible(true);
gui.getContentPane().add(loadbar);
gui.setVisible(true);
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setLocationRelativeTo(null);
for(int i=0;i<=100;i++)
{
loadbar.setValue(i);
try
{
Thread.sleep(15);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}