久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

爪哇.拖動&將 ImageIcon 從面板 1 上的 JLabel

Java. Drag amp; Drop ImageIcon from JLabel on panel 1, to JLabel on panel 2. Add Counter function(爪哇.拖動amp;將 ImageIcon 從面板 1 上的 JLabel 拖放到面板 2 上的 JLabel.添加計數器功能) - IT屋-程序員軟件開發技術
本文介紹了爪哇.拖動&將 ImageIcon 從面板 1 上的 JLabel 拖放到面板 2 上的 JLabel.添加計數器功能的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我已經實現了這個非常基本的,在兩個 JPanel 之間拖放,但這并不能真正滿足我的要求!

I've implemented this very basic, drag and drop between two JPanels, but this doesn't really meet my requirements!

public class test extends JFrame {

{    JPanel mainpanel, storypanel, imageselect;



    public test(){

          mainpanel = new JPanel(new BorderLayout());
          storypanel = new JPanel();
          imageselect = new JPanel();
            MouseListener listener = new MouseAdapter(){
            public void mousePressed(MouseEvent e)
        {
            JComponent c = (JComponent) e.getSource();
            TransferHandler handler = c.getTransferHandler();
            handler.exportAsDrag(c, e, TransferHandler.COPY);
        }
        };

            int j = 0;
            BufferedImage myImages;
            JLabel imgselect = new JLabel();
            try { myImages = ImageIO.read(new File("four.jpg"));
            //myImages[j] = resize(myImages[j]);
            imgselect= new JLabel(new ImageIcon(myImages));
            System.out.println(j);
            imageselect.add(imgselect);
            imgselect.addMouseListener(listener);
            imgselect.setTransferHandler(new TransferHandler("icon"));

            } catch(Exception e) {};

            int i = 0;
            BufferedImage storyimages;
            JLabel storylabel = new JLabel();


            //targetImg = new ImageIcon("lmkpackage/base/TargetImg.jpg");
            try{ storyimages = ImageIO.read(new File("TargetImg.jpg"));
            //storyimages[i] = resize(storyimages[i]);
            storylabel = new JLabel(new ImageIcon(storyimages));
            System.out.println(i);
            storypanel.add(storylabel); 
            storylabel.addMouseListener(listener);
            storylabel.setTransferHandler(new TransferHandler("icon"));
            } catch(Exception e) {};


            mainpanel.add(imageselect, BorderLayout.NORTH);
            mainpanel.add(storypanel, BorderLayout.SOUTH);

            getContentPane().add(mainpanel);



        }

        public static void main(String[] args){

        System.out.println("Application Running");
        JFrame mainframe =  new test();
            mainframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mainframe.setSize(1000,1000);
            mainframe.setVisible(true);

        }

    }

對不起,我在這里不是很清楚.我試圖將 ImageIcon 從圖像選擇面板上的 JLabel 拖到故事情節面板的另一個 JLabel 上.我可以用上面的代碼做到這一點.但是當我這樣做時,我可以從圖像選擇面板中拖動一個 ImageIcon,并在同一面板上替換另一個 ImageIcon.我不希望這種情況發生.我也可以從故事情節面板拖動到圖像選擇面板,這是我不想要的.

Sorry I wasn't very clear here. Im trying to drag an ImageIcon from a JLabel on the imageselect panel, to another JLabel the storyline panel. I can do this, with the above code. But when I do this, I can drag an ImageIcon from the imageselect panel, and replace another ImageIcon on the same panel. I do NOT want this to happen. I can also drag from the storyline panel to the imageselect panel, which I do NOT want.

我不是要求被勺子喂食代碼,我只是在尋找正確方向的推動力!

I'm not asking to be spoon fed code, I'm just looking for a push in the right direction!

我想知道是否有任何方法可以計算成功的拖放操作,下面的解決方案回答了我原來的問題.

I'm wondering is there any way of counting a successful drag and drop operation, the solution below answered my original question.

推薦答案

這基本上是@Andrew 評論的大綱 - 由于您的 SSCCE 很容易實現 :-)

This is basically an outline of @Andrew's comment - easily possible due to your SSCCE :-)

子類 TransferHandler,覆蓋 canImport 以檢查源標簽是否在 imageSelect 面板上,如果是則拒絕.

Subclass TransferHandler, override canImport to check if the source label is on the imageSelect panel and reject if so.

    // custom transferHandler which decides about imports based on source
    TransferHandler handler = new TransferHandler("icon") {

        @Override
        public boolean canImport(TransferSupport support) {
            return super.canImport(support) 
                    && support.getComponent().getParent() != imageSelectPanel;
        }

    };
    // use the handler on all labels (handlers can be shared, btw)
    // for each label on imageSelectPanel
    imageSelectLabel.setTransferHandler(handler)
    // for each label on the target panel (aka storyPanel) 
    storyLabel.setTransferHandler(handler)

這篇關于爪哇.拖動&將 ImageIcon 從面板 1 上的 JLabel 拖放到面板 2 上的 JLabel.添加計數器功能的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 日韩不卡视频在线 | 自拍偷拍第一页 | 国产精品夜夜春夜夜爽久久电影 | 亚洲精品国产电影 | 国产一级片网站 | 亚洲精品一区二区三区蜜桃久 | 天天天天操| 中文字幕一区二区三区四区五区 | 国产高清在线 | 国产精品久久久久一区二区三区 | 先锋资源亚洲 | 成人欧美一区二区三区在线播放 | 成人国产午夜在线观看 | 久亚州在线播放 | 爱综合 | 久久综合一区二区三区 | 日韩在线小视频 | 日韩精品免费播放 | 亚洲www啪成人一区二区 | 久久亚洲一区 | 综合久| 中文字幕一区二区三区在线观看 | 亚洲视频欧美视频 | 亚洲精选一区二区 | 91成人精品 | 亚洲视频免费观看 | 国产高清在线观看 | a在线免费观看视频 | 亚洲精品在线免费观看视频 | 一区二区三区国产好 | av免费看片 | 二区在线视频 | 国产精品欧美一区二区 | 久久久久国产精品一区二区 | 久草免费福利 | 日韩在线免费播放 | 视频一区二区在线观看 | 亚洲精品高清视频在线观看 | 国产在线视频99 | 久久久久亚洲 | 毛片区|