0

我有以下 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()checkMark.isOptimizedDrawingEnabled()我将如何处理这个,将元素放在前面?

4

1 回答 1

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);

                }
于 2013-05-22T17:08:34.937 回答