java - JLabel setLocation not working? -


here code have written:

super("add contact");  setlayout(new flowlayout()); ipaddress = new jlabel("ip address"); ipaddress.setlocation(1000, 100);  imageicon ii=new imageicon(getclass().getresource("add.png")); jlabel image = new jlabel(ii); image.setsize(100, 100); image.setlocation(500, 100); add(image); add(ipaddress); setsize(500,150); } 

that correct. layout manager responsible setting location of component based on rules of layout manager. in case flowlayout override location of component.

you should never hardcode location of component. if using resolution less 1024 x 768? component never show.

you should never set size of component. every component has preferred size. in case of label image, preferred size size of image.

read on layout managers , use appropriate layout manager or combination of layout managers achieve desired layout.


Comments

Popular posts from this blog

go - serving up pdfs using golang -

python - Best design pattern for collection of objects -

r - Using `bbmle:mle2` with vector parameters (already works using `optim`) -