java - JPanel: What is the simplest way to display an image? -


i working on project , need display image have drawn. need background image , several foreground images can move around. easiest way this? haven't been able find clear answer.

imageicon image = new imageicon("imagename.jpg");     jlabel label = new jlabel("", image, jlabel.center);     jpanel panel = new jpanel(new borderlayout());     panel.add( label, borderlayout.center );     return panel; 

the answer depends. want resize background image meet requirements of client or not? if so, want "fill" or "fit" image area.

take @ java: maintaining aspect ratio of jpanel background image lengthier discussion on topic.

the next question need ask, want paint animation on surface or use existing components , move them instead...

you check out...

which uses paintcomponent or direct paint method.

this approach relatively common , easy control. problem if want perform sub animation (ie animate element separately main animation...think walking or spinning), becomes more difficult.

check out

which uses components instead. method if want provide sub animation, has complexity of requiring size , position components within container.

just side note. jlabel container ;)


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -