今、JButtonのかわりに下のコードのインナークラスを使っていますが、setText()で文字列を表示できなくなりました。
なんとなく、paintComponent(Graphics g)
とかその辺が原因なのかなーくらいには思っていますが、調べようにも何を検索していいのかわかりません。
助けてください。
java
1 2 private Image img; 3 public int alpha; //0~255 volatile? 4 public int width; 5 public int height; 6 private boolean size; 7 8 public FButton(){ 9 10 size = false; 11 } 12 13 public FButton(String str){ 14 15 this.setText(str); 16 size = false; 17 } 18 19 public FButton(ImageIcon icon){ 20 21 setIconAndImage(icon); 22 size = false; 23 } 24 25 public void setIconAndImage(ImageIcon icon){ 26 27 setIcon(icon); 28 if(icon != null) img = icon.getImage(); 29 else img = null; 30 } 31 32 public void setIconSize(int w, int h){ 33 34 this.width = w; 35 this.height = h; 36 size = true; 37 } 38 39 public void paintComponent(Graphics g){ 40 41 if(img != null){ 42 43 Graphics2D g2 = (Graphics2D)g; 44 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)alpha / (float)255)); 45 46 if(!size) g2.drawImage(img, 0, 0, getIcon().getIconWidth(), getIcon().getIconHeight(), this); 47 else g2.drawImage(img, 0, 0, width, height, this); 48 } 49 } 50 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。