質問編集履歴
1
情報追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -141,3 +141,127 @@
|
|
141
141
|
}
|
142
142
|
|
143
143
|
```
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
追記:
|
148
|
+
|
149
|
+
実際に作っているプログラムの一部です。
|
150
|
+
|
151
|
+
`setIconSize(w, h);`のあとに`setBounds();`を使っているのでrepaintされていると思います。
|
152
|
+
|
153
|
+
念のためsetBoundsのあとに`repaint()`を入れてみてもなにも変わりませんでした。
|
154
|
+
|
155
|
+
wとh両方が自然数ならば正常に動きますが、100%毎回ではないようです。
|
156
|
+
|
157
|
+
どちらか片方、又は両方が0以下なら100%paintComponentは呼ばれません。
|
158
|
+
|
159
|
+
```java
|
160
|
+
|
161
|
+
JTextArea text;
|
162
|
+
|
163
|
+
ImageIcon dispImage;
|
164
|
+
|
165
|
+
FLabel imgLabel;
|
166
|
+
|
167
|
+
/*****************************************************/
|
168
|
+
|
169
|
+
if(text.getText().startsWith("image:")){ //画像
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
String str = text.getText().substring(6);
|
174
|
+
|
175
|
+
if(!str.equals("null")){
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
str = "img/" + str;
|
180
|
+
|
181
|
+
File img = new File(str);
|
182
|
+
|
183
|
+
if(img.exists()){
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
dispImage = new ImageIcon(str);
|
188
|
+
|
189
|
+
imgLabel.setIconAndImage(dispImage);
|
190
|
+
|
191
|
+
if(!imgLabel.size) imgLabel.setBounds(50, 50, dispImage.getIconWidth(), dispImage.getIconHeight());
|
192
|
+
|
193
|
+
else imgLabel.setBounds(50, 50, imgLabel.iwidth, imgLabel.iheight);
|
194
|
+
|
195
|
+
} else{
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
text.setText("\"" + str + "\" is not found!");
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
} else if(imgLabel.getIcon() != null){
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
imgLabel.setIconAndImage(null);
|
208
|
+
|
209
|
+
dispImage = null;
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
} else if(text.getText().startsWith("image.")){
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
String txt = text.getText().substring(6);
|
218
|
+
|
219
|
+
if(txt.startsWith("position:")){
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
txt = txt.substring(9);
|
224
|
+
|
225
|
+
int w = number(txt);
|
226
|
+
|
227
|
+
txt = txt.substring(new String(w + "").length() + 1);
|
228
|
+
|
229
|
+
int h = number(txt);
|
230
|
+
|
231
|
+
//wとhには幅と高さの整数が入っています。
|
232
|
+
|
233
|
+
imgLabel.setBounds(w - imgLabel.getWidth() / 2, h - imgLabel.getHeight() / 2, imgLabel.getWidth(), imgLabel.getHeight());
|
234
|
+
|
235
|
+
}else if(txt.startsWith("size:")){ //表示サイズの指定
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
txt = txt.substring(5);
|
240
|
+
|
241
|
+
int w = number(txt);
|
242
|
+
|
243
|
+
txt = txt.substring(new String(w + "").length() + 1);
|
244
|
+
|
245
|
+
int h = number(txt);
|
246
|
+
|
247
|
+
//wとhには幅と高さの整数が入っています。
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
imgLabel.setIconSize(w, h);
|
252
|
+
|
253
|
+
imgLabel.setBounds(w - imgLabel.getWidth() / 2, h - imgLabel.getHeight() / 2, imgLabel.iwidth, imgLabel.iheight);
|
254
|
+
|
255
|
+
imgLabel.setIconAndImage(dispImage);
|
256
|
+
|
257
|
+
} else if(txt.equals("bounds")){
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
text.setText("X:" + (imgLabel.getX() + imgLabel.getWidth() / 2) + ", Y:" + (imgLabel.getY() + imgLabel.getHeight() / 2) + ", width:" + imgLabel.getWidth() + ", height:" + imgLabel.getHeight());
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
```
|