java - JPanel Obscures BufferedImage -


i'm having trouble finding out why following problem happens: in program uses "extends frame" create window, can use bufferedimage draw graphics context of frame (not jframe), , looks fine. however, moment declare jpanel, of text drawn bufferedimage becomes obscured (not completely, semi-transparent , hard read), if don't add jpanel jframe.

here's simplified version of code:

import java.awt.*; import java.awt.event.*; import javax.swing.timer; import java.awt.image.*; import javax.swing.*;  public class myprogram extends frame {      static frame f;     static timer timer;      public static void main(string[] args) {          f = new frame();         f.setsize(400, 200);         f.setresizable(false);         f.setvisible(true);          f.addkeylistener(new keyadapter() {          public void keypressed(keyevent e) {              drawscreen();         }     });      drawscreen(); }  public static void drawscreen() {      bufferedimage off_i = new bufferedimage(f.getwidth(), f.getheight(), bufferedimage.type_int_rgb);     graphics g = off_i.creategraphics();      g.setcolor(new color(50, 50, 50));     g.drawstring("hit key; why text change?", 15, f.getheight() - 10);      graphics off_g = f.getgraphics();     off_g.drawimage(off_i, 0, 0, null);      jpanel panel = new jpanel();     } } 

i maybe understand seeing problem arise if had added jpanel jframe , didn't set bounds visibility, creating jpanel gives issue, seems weird me.

basically, i'm trying here take existing program have runs fine without jpanel, , want add jtextarea can accept copy/paste text modifying displaying of program.

my understanding of java kind of spotty, learned hobby , not formally, i'm looking learn more when can. help!

update: discovered problem happens when draw function called again, after jpanel has been declared, though still don't understand why or how around it.

better put image jlabel , how ot use icon

please read using swing components , how layoutmanagers works

tons examples on java2s.com


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -