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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -