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

python - What's the Pythonic way to report nonfatal errors in a parser? -

sql server - Deadlock occuring in Clustered Columnstore index -

php - curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to domain.com:443 -