+ 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

6th Apr 2019, 6:18 AM
Immortal Crow
Immortal Crow - avatar
5 Answers
+ 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);
6th Apr 2019, 7:03 AM
JavaBobbo
JavaBobbo - avatar
+ 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
6th Apr 2019, 1:56 PM
Immortal Crow
Immortal Crow - avatar
+ 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);
6th Apr 2019, 2:56 PM
JavaBobbo
JavaBobbo - avatar
+ 1
:) :) :) it is working now .... Thank You So much .......
6th Apr 2019, 3:21 PM
Immortal Crow
Immortal Crow - avatar
0
You welcome 😊
6th Apr 2019, 3:35 PM
JavaBobbo
JavaBobbo - avatar