java - Why will image not add when JFrame has .setSize -


i'm novice programmer , i'm have trouble adding image frame. while know how add images generally, specific case not work.

public class tutorial extends jframe{      tutorial(){          jframe frame = new jframe("imagetutorial");         frame.setvisible(true);         frame.setsize(750,850);         frame.setdefaultcloseoperation(jframe.exit_on_close);         frame.setlayout(null);         imageicon image = new imageicon(getclass().getresource("green block.png"));         jlabel imagelabel = new jlabel(image);         imagelabel.setbounds(10, 10, 75, 75);         imagelabel.setopaque(true);         frame.add(imagelabel);   

now, i've located problem don't understand 'why' problem. when remove

        frame.setsize(750,850); 

the image shows, when there doesn't. how can frame's size impact image showing , how can around it?

just curious, logically, makes think frame should visible before add components? logically speaking, wouldn't seem right add components first, then make frame visible. it's displaying painting in art gallery before painter has painted on it. makes no sense. highly doubt setting size has it. if don't set size of frame, frame appears small possible. when resize frame, causes repaint, then showing label add. but generally, want set frame visible after components added, avoid problem.

side note: should stay away null layouts. need learn use layout managers , let them dynamic sizing , locating you.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -