当我改变高度/宽度时图像消失

时间:2013-05-22 14:16:38

标签: java

我有以下Java代码:

public void actionPerformed(ActionEvent e)
        {
            ImageIcon i1 = new ImageIcon("/Users/vhaislsalisc/Documents/workspace/Role_Switcher/greenCheck.png", "Success!");
            JLabel checkMark = new JLabel(i1);


            if (requesterRole.isSelected())
            {
                try
                {
                    PreparedStatement ps1, ps2;
                    ps1 = con.prepareStatement("delete from hib.personrole where personid = ?");
                    ps2 = con.prepareStatement("delete from hib.persongroup where personid = ?");

                    ps1.setInt(1, userID);
                    ps2.setInt(1, userID);

                    ps1.execute();
                    ps2.execute();

                    userRoleLbl.setText("The user is a requester");

                    checkMark.setBounds(400, 125, 100, 100);
                    panel.add(checkMark);


                }

我的图像是200x200像素。当我更改checkMark.setBounds()高度或宽度时,图像会消失。但是,我现在所拥有的只是显示图像的一部分。我确信我做错了什么,我根本不知道那可能是什么。

它几乎看起来像是在另一个元素后面,虽然屏幕上没有任何元素延伸到那么远。我查找了一个元素到前面,有人建议我这样做,我需要覆盖isOptimizedDrawingEnabled()false,然后我在checkMark.setBounds()下添加{{1}我将如何处理这个问题,将元素放在前面?

1 个答案:

答案 0 :(得分:0)

我编辑的代码看起来像这样,并且有效:

//Create Success Image
            ImageIcon i1 = new ImageIcon("/Users/vhaislsalisc/Documents/workspace/Role_Switcher/greenCheck.png");
            i1.paintIcon(changeRoleBtn, getGraphics(), 400,25);
            JLabel checkMark = new JLabel(i1);
            checkMark.isOptimizedDrawingEnabled();

            if (requesterRole.isSelected())
            {
                try
                {
                    PreparedStatement ps1, ps2;
                    ps1 = con.prepareStatement("delete from hib.personrole where personid = ?");
                    ps2 = con.prepareStatement("delete from hib.persongroup where personid = ?");

                    ps1.setInt(1, userID);
                    ps2.setInt(1, userID);

                    ps1.execute();
                    ps2.execute();

                    userRoleLbl.setText("The user is a requester");
                    panel.add(checkMark);

                }