我在JTextArea
背景上绘制图像,它使用其他外观和感觉(金属,Windows等)绘制,但当我使用Nimbus
外观和感觉它不绘制图像可能的问题是什么以及如何解决这个问题?这是我正在使用的代码
Image TextArea类
public class ImageTextArea extends JTextArea{
File image;
public ImageTextArea(File image)
{
setOpaque(false);
this.image=image;
}
@Override
public void paintComponent(final Graphics g)
{
try
{
// Scale the image to fit by specifying width,height
g.drawImage(new ImageIcon(image.getAbsolutePath()).getImage(),0,0,getWidth(),getHeight(),this);
super.paintComponent(g);
}catch(Exception e){}
}
}
Run Code Online (Sandbox Code Playgroud)
和Test类
public class TestImageTextArea extends javax.swing.JFrame {
private ImageTextArea tx;
public TestImageTextArea() {
tx = new ImageTextArea(new File("img.jpg"));
setTitle("this is a jtextarea with image");
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel mainp = new JPanel(new BorderLayout());
add(mainp);
mainp.add(new JScrollPane(tx), …
Run Code Online (Sandbox Code Playgroud) 我得到了例外
java.lang.NoSuchFieldError: reportUnusedDeclaredThrownExceptionIncludeDocCommentReference outside eclipse in command line using maven.
在GWT库的依赖列表的顶部声明和GWT 2.5.1正在使用.如何解决这个问题?请帮忙
我想防止从JTextArea
. 做到这一点的最佳方法是什么?我找到了一个KeyListner
解决方案,但似乎不是最好的。我不想为此使用密钥侦听器。有我可以使用的快捷方法/方式吗?
我试图显示一段时间后内容发生变化的图像.我正在显示它JLabel
,但问题是当我重新加载这个图像它没有改变,JLabel
因为似乎JLabel#setIcon(new ImageIcon("myImagePath.png"));
缓存图像在内存中,当我改变它,它寻找名称,并没有从硬盘加载它.
即使我使用两个图像来翻转其数据内容是否已更改?谁知道如何解决这个问题?但每次加载不同名称的图像都可以正常工作?
创建问题的行: 例如我的图像在按钮单击事件上更改
jlabel.setIcon("d:\\img.png");
jlabel.repaint();
Run Code Online (Sandbox Code Playgroud) 好的,所以我正在关注BrandonioProdtuctions YouTube频道的Java教程.我在第7部分:面向对象编程简介.我遇到的问题是,当我尝试运行程序时,它会给我在类中的错误(标题为objectIntroTest),我在下面直接粘贴了它.
public class objectIntroTest {
public static void main(String[] args){
String x = "Hello";
objectIntro waterBottle = new objectIntro(0);
waterBottle.addwater(100);
waterBottle.drinkWater(20);
System.out.println("Your remaining water level is:"* + waterBottle.getWater());
}
}
Run Code Online (Sandbox Code Playgroud)
这是另一个名为"objectIntro"的类:
public class objectIntro {
public objectIntro(){
//Default constructor
}
public objectIntro(int waterAmount){
twater = waterAmount;
}
int twater = 0; //This is how much water is in the water bottle
public void addWater(int amount){
twater = twater + amount;
}
public void drinWater(int amount){
twater = twater …
Run Code Online (Sandbox Code Playgroud) 我试图从POST得到响应,但当我做输入throws
和exception
try {
conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
// Marcamos a 3s el tiempo maximo de espera
conn.setReadTimeout(30000000);
conn.setUseCaches(true);
conn.setFixedLengthStreamingMode(bytes.length);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded;charset=UTF-8");
// post the request
// Abrimos una señal de salida
OutputStream out = conn.getOutputStream();
out.write(bytes);
out.flush();
String buffer;
// Abrimos una señal de entrada
here is where android throws and exception
InputStreamReader ip = new InputStreamReader(conn.getInputStream());
BufferedReader in2 = new BufferedReader(ip);
// Bucle que recoge todas las respuestas
while ((buffer = in2.readLine()) != …
Run Code Online (Sandbox Code Playgroud)