小编a q*_*ion的帖子

使用Nimbus Look And Feel时,无法在JTextArea背景上绘制图像

我在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 swing background-image jtextarea

2
推荐指数
1
解决办法
1035
查看次数

java.lang.NoSuchFieldError:reportUnusedDeclaredThrownExceptionIncludeDocCommentReference

我得到了例外

java.lang.NoSuchFieldError: reportUnusedDeclaredThrownExceptionIncludeDocCommentReference outside eclipse in command line using maven.

GWT库的依赖列表的顶部声明和GWT 2.5.1正在使用.如何解决这个问题?请帮忙

javascript java gwt exception smartgwt

2
推荐指数
1
解决办法
2353
查看次数

在 JTextArea 上防止 Ctrl+c 的最佳方法

我想防止从JTextArea. 做到这一点的最佳方法是什么?我找到了一个KeyListner 解决方案,但似乎不是最好的。我不想为此使用密钥侦听器。有我可以使用的快捷方法/方式吗?

java clipboard swing copy jtextarea

1
推荐指数
1
解决办法
1428
查看次数

在JLabel中刷新相同的图像

我试图显示一段时间后内容发生变化的图像.我正在显示它JLabel,但问题是当我重新加载这个图像它没有改变,JLabel因为似乎JLabel#setIcon(new ImageIcon("myImagePath.png"));缓存图像在内存中,当我改变它,它寻找名称,并没有从硬盘加载它.

即使我使用两个图像来翻转其数据内容是否已更改?谁知道如何解决这个问题?但每次加载不同名称的图像都可以正常工作?

创建问题的行: 例如我的图像在按钮单击事件上更改

jlabel.setIcon("d:\\img.png");
jlabel.repaint();
Run Code Online (Sandbox Code Playgroud)

java swing jlabel imageicon

1
推荐指数
1
解决办法
4741
查看次数

错误说我的方法未定义

好的,所以我正在关注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)

java

0
推荐指数
1
解决办法
178
查看次数

来自POST的getInputStream时的JAVA EOFException

我试图从POST得到响应,但当我做输入throwsexception

     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)

java post android exception

0
推荐指数
1
解决办法
3567
查看次数