java - Why don't I see the image or the button? -


i trying add button on image. neither see button nor image. why ? calling method constructor after initcomponents method called ide.

public void initd() {     try {         bufferedimage mypicture = imageio.read(new file("c:\\users\\user\\documents\\netbeansprojects\\javaapplication1\\src\\javaapplication1\\meaning.jpg"));         jlabel piclabel = new jlabel(new imageicon(mypicture));         jbutton b = new jbutton("press me");         jpanel1.add(piclabel);         jpanel1.add(b);         system.out.println("last statement");     }catch(exception exc) {         exc.printstacktrace();     } } 

i see frame output.

i dont know layout using, should implement button.seticon(); this;

public void initd() {     jbutton button = new jbutton("press me");     try {         bufferedimage mypicture = imageio.read(new file("c:\\users\\user\\documents\\netbeansprojects\\javaapplication1\\src\\javaapplication1\\meaning.jpg"));         jlabel piclabel = new jlabel(new imageicon(mypicture));          button.seticon(new imageicon(mypicture));          system.out.println("last statement");     }catch(exception exc) {         exc.printstacktrace();     } } 

in addition may need consider resource of image maybe implemantation can helpfull ;

imageio.read(getclass().getresource("resources/meaning.jpg"))); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -