+ 2
java jframe
i can't call import javax.swing.*; and my java jframe setBound() is not working although i use setLayout(null); please give me advice
5 Respostas
+ 2
You sure you used it correctly?
theComponent.setBounds(x,y,width,height);
And did you add the import above the class?
And did you add the component to your frame?
frame.add(component);
+ 1
Thank for answer my question....here my code
package calculator;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Calculator {
public static void main(String[] args) {
JFrame j=new JFrame("Calculator");
JLabel l1=new JLabel("firstNumber");
l1.setBounds(40, 200, 100, 35); /*Although i change value of x and y it is not working ...."firstNumber" is always show in same location at lefttop conner of frame */
j.add(l1);
j.setVisible(true);
j.setLayout(null);
j.setSize(400, 600);
}
}
// please give me advice
+ 1
You need to use the setLayout before you set the frame size
j.setLayout(null);
j.setSize(400, 600);
j.setVisible(true);
And add this so the frame really get closed:
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Without this the frame will still be in the background
You can also add this if you want to center your frame:
j.setLocationRelativeTo(null);
+ 1
:) :) :) it is working now .... Thank You So much .......
0
You welcome 😊