Omnimaga
General Discussion => Technology and Development => Computer Programming => Topic started by: Munchor on February 25, 2011, 01:50:15 pm
-
package gamepanel;
import javax.swing.*;
public class Main {
public static void main(String[] args) {
JFrame loadingBarFrame = new JFrame();
loadingBarFrame.setSize(400,100);
loadingBarFrame.setVisible(true);
JProgressBar progressBar = new JProgressBar();
progressBar.setVisible(true);
progressBar.setLocation(5,5);
progressBar.setSize(1000,1000);
progressBar.setValue(0);
progressBar.setStringPainted(true);
}
}
I have this code which is supposed to create a simple progress bar and a frame, however, the progress bar doesn't appear for some obvious reason I'm not aware of, any ideas?
-
are you sure that it is rendering the screen correctly? you see, if you were using netbeans instead it has a built in editor that lets you actually place the buttons and bars and such manually in a graphical way ;)
-
are you sure that it is rendering the screen correctly? you see, if you were using netbeans instead it has a built in editor that lets you actually place the buttons and bars and such manually in a graphical way ;)
I know, but I'm not using that. I'm programming the GUI, I only use that for big frames and complicated stuff.
-
interesting, it looks like you're doing it correctly...
-
Hmmm it seems that you create the progress bar, but it never interacts with the loadingBarFrame. I am not very familiar with swing components, do you need to add it into the frame or whatnot?
-
Hmmm it seems that you create the progress bar, but it never interacts with the loadingBarFrame. I am not very familiar with swing components, do you need to add it into the frame or whatnot?
Thanks, the .add( method did it ;D
-
hah yay :D glad I was able to help ^^
-
Yeah, and I would be careful with just using .add(. In fact, what I do is create what I want in netbeans and study the code for it.
Also, Builderboy, you have +256 respect (2^8), and are 17 posts away from 4096 (2^12)
-
Yeah, and I would be careful with just using .add(. In fact, what I do is create what I want in netbeans and study the code for it.
Also, Builderboy, you have +256 respect (2^8), and are 17 posts away from 4096 (2^12)
I do hate add(, so in the tiny program I just made (Catalan Number GUI) I decided to use the NetBeans IDE, but the designer is quite bad when compared to Visual Studio's or Sharp Develop's. Sometimes the window resizes itself, and it won't let me make what I want.
-
in this situation the code would be
loadingBarFrame.getContentPane().add(progressBar);
however, because the java swing designers realized having to call getContentPane() everytime you want to add a component to a frame, they made it so loadingBarFrame.add(progressBar); will automatically add progressBar to the content pane. learning to use a layout like SpringLayout is the best solution.