java - Swing text field visibility issue -
i trying make frame , add text field inside it. used jtextfield
. it's not appearing.
code
import java.awt.*; import javax.swing.*; class tst { jframe f; jtextfield tf; public tst() { f=new jframe(); tf=new jtextfield(10); f.setsize(400,400); f.add(tf); f.setlayout(null); f.setvisible(true); } public static void main(string s[]) { new tst(); } }
if don't want use layout manager, need set bounds using jtextfield
's setbounds(x, y, width, height)
method, x
, y
position of textfield in jframe
:
tf.setbounds(100 , 100 , 100 , 20 );
first set layout frame, add elements , components it, in full code:
import javax.swing.*; class tst { public tst() { jtextfield tf = new jtextfield(10); tf.setbounds(100 , 100 , 100 , 20 ); jframe f = new jframe(); f.setsize(400, 400); f.setlayout(null); f.setvisible(true); f.add(tf); f.setdefaultcloseoperation(jframe.exit_on_close); } public static void main(string s[]) { new tst(); } }
Comments
Post a Comment