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

JDK1.6和JDK1.7的拖放區別

Drag and drop differences between JDK1.6 and JDK1.7(JDK1.6和JDK1.7的拖放區別)
本文介紹了JDK1.6和JDK1.7的拖放區別的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

有人知道 JDK1.6 和 JDK1.7 之間拖放行為的差異嗎?在將 URL 從瀏覽器拖放到需要支持 JDK1.5、JDK1.6 和 JDK1.7 的應用程序上時,我遇到了一個差異(如下所示).我現在想知道是否存在其他差異,以及它們是否記錄在某處.

Does anybody know about differences in the drag-and-drop behavior between JDK1.6 and JDK1.7 ? I encountered a difference (illustrated below) when drag-and-dropping an URL from a browser onto an application which needs to support JDK1.5, JDK1.6 and JDK1.7 . I am now wondering whether other differences exists and if they are documented somewhere.

我遇到的不同行為是通過單擊并將 URL 從瀏覽器(不是從地址欄而是從頁面)拖放到 Java 應用程序上來拖放 URL.在 JDK1.6 上,Transferable 不支持 DataFlavor.javaFileListFlavor 而在 JDK1.7 上它支持(盡管在請求其傳輸數據時會得到一個空列表).下面的代碼說明了這個問題.它會打開一個 JFrame,您可以在其中拖放一個 URL,例如 http://www.google.com 并打印出它是使用文件列表風格還是 URI 列表風格

The different behavior I encountered is when drag-and-drop an URL from a browser (not from the address bar but from the page) by click-and-drag the URL onto the Java application. On JDK1.6, the Transferable does not support the DataFlavor.javaFileListFlavor and on JDK1.7 it does (although when requesting for its transfer data you get an empty list). The following code illustrates the issue. It opens a JFrame on which you can drag-and-drop an URL like http://www.google.com and which prints out whether it uses the file list flavor or the URI-list flavor

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.TransferHandler;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

public class DragAndDropTester {
  private static DataFlavor URI_LIST_FLAVOR = null;

  static {
    try {
      URI_LIST_FLAVOR = new DataFlavor( "text/uri-list;class=java.lang.String" );
    }
    catch ( ClassNotFoundException ignore ) {
    }
  }
  public static void main( String[] args ) {
    try {
      EventQueue.invokeAndWait( new Runnable() {
        public void run() {

          JFrame testFrame = new JFrame( "Test" );

          JPanel contents = new JPanel( new BorderLayout() );
          contents.add( new JLabel( "TestLabel" ), BorderLayout.CENTER );

          contents.setTransferHandler( createTransferHandler() );

          testFrame.getContentPane().add( contents );
          testFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
          testFrame.setSize( 200, 200 );
          testFrame.setVisible( true );
        }
      } );
    } catch ( InterruptedException e ) {
      throw new RuntimeException( e );
    } catch ( InvocationTargetException e ) {
      throw new RuntimeException( e );
    }
  }

  private static TransferHandler createTransferHandler(){
    return new TransferHandler(  ){
      @Override
      public boolean importData( JComponent comp, Transferable aTransferable ) {
        try {
          if ( aTransferable.isDataFlavorSupported( DataFlavor.javaFileListFlavor ) ) {
            System.out.println("File list flavor");
            List<File> file_list = ( List<File> ) aTransferable.getTransferData( DataFlavor.javaFileListFlavor );
            System.out.println( "file_list = " + file_list );
          }
              if ( URI_LIST_FLAVOR != null && aTransferable.isDataFlavorSupported( URI_LIST_FLAVOR ) ){
            System.out.println("URI list flavor");
            String uri_list = ( String ) aTransferable.getTransferData( URI_LIST_FLAVOR );
            System.out.println( "uri_list = " + uri_list );
          }
        } catch ( UnsupportedFlavorException e ) {
          throw new RuntimeException( e );
        } catch ( IOException e ) {
          throw new RuntimeException( e );
        }
        return true;
      }

      @Override
      public boolean canImport( JComponent comp, DataFlavor[] transferFlavors ) {
        return true;
      }
    };
  }
}

JDK 1.7.01 上的結果輸出

Resulting output on JDK 1.7.01

File list flavor
file_list = []
URI list flavor
uri_list = http://www.google.com

JDK1.6.0.18 上的結果輸出

Resulting output on JDK1.6.0.18

URI list flavor
uri_list = http://www.google.com

我可以輕松地為這個問題創建一個解決方法,但我對更多已知的差異和/或關于這些差異的文檔更感興趣.

I can easily create a workaround for this issue, but I am more interested in any more know differences and/or documentation about those differences.

編輯

一些進一步的調查/谷歌搜索讓我認為 JDK7 上的行為是創建 URI 和文件列表數據風格,并在可傳輸中提供它們.然后文件列表只包含代表文件的 URI.因此,僅拖放 URL 時,文件列表為空.我在 JDK 源代碼中找不到這個,因為似乎可傳輸/傳輸數據是用本機代碼創建的(或者至少是我找不到源代碼的代碼).在 OpenJDK 郵件列表上有一個關于 類似問題的討論,包含以下引用

Some further investigation/googling makes me think the behavior on JDK7 is to create both the URI and filelist data flavor and offering them both in the transferable. The filelist then only contains the URI's which represent a file. Hence when only drag-and-dropping an URL, the file list is empty. I cannot find this in the JDK source code as it seems the transferable/transferdata is created in native code (or at least code for which I do not find the sources). On the OpenJDK mailing list there was a discussion about a similar issue, containing the following quote

如果您將文件列表從本機拖到 Java 中,應用程序會同時看到 URI 列表和文件列表.如果你拖入一個 URI 列表,它會看到一個 URI 列表,如果所有 URI 都是文件,那么它也是一個非空文件列表,否則只是一個空文件列表.

If you drag a file list from native into Java, the application sees both a URI list and a file list. If you drag in a URI list it sees a URI list, and if all URIs are files also a non-empty file list, otherwise just an empty file list.

編輯2

根據 serg.nechaev 的回答,我在 32/64 位 Linux 系統和幾個 Windows 系統(從 XP 到 Windows7)上進行了更多測試.在帶有 JDK7 的 Linux 上,我總是得到 URI 數據風格,以及空文件列表風格.在 Windows 上,我得到一個 URI 數據風格和一個非空文件列表數據風格.似乎在臨時目錄中創建了一個 .URL 文件,并且這也是在文件列表數據風格中傳遞的,這在 JDK 6 上不是這種情況.

Based on the answer of serg.nechaev I performed some more tests on 32/64 bit Linux systems and several Windows system (ranging from XP to Windows7). On Linux with JDK7 I always get the URI dataflavor, combined with an empty filelist flavor. On Windows, I get a URI dataflavor and a non-empty filelist data flavor. It seems a .URL file gets created in the temp dir, and this is passed in the filelist data flavor as well, which wasn't the case on JDK 6.

所有這些情況的解決方案是首先檢查 URI 數據風格,然后使用文件列表數據風格作為后備

Solution in all these cases is to check for the URI dataflavor first, and use the file list data flavor as fall-back

推薦答案

我認為導致此行為的更改在 $(JDK)/jre/lib/flavormap.properties:

I think the change that caused this behaviour is in $(JDK)/jre/lib/flavormap.properties:

http://hg.openjdk.java.net/jdk7/hotspot-gc/jdk/diff/fd5bf5955e37/src/windows/lib/flavormap.properties

但是,使用您的示例并從您的帖子中拖動到 Google 的鏈接,我得到了文件列表和WinXP、FireFox 8 上 JDK 1.7.0 上的 uri 列表:

However, using your sample and dragging a link to Google from your post, I am getting both file list & uri list on JDK 1.7.0 on WinXP, FireFox 8:

File list flavor
file_list = [C:DOCUME~1SERGNLOCALS~1Temphttpwww.google.com.URL]
URI list flavor
uri_list = http://www.google.com/

這可能是 JDK 1.7.01 的特定于平臺的錯誤,您可能需要進一步調查,并可能向 Oracle 提交錯誤.

That could be a platform-specific bug for JDK 1.7.01, you might want to investigate it further and maybe submit a bug to Oracle.

這篇關于JDK1.6和JDK1.7的拖放區別的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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:獲取當前星期幾的值)
主站蜘蛛池模板: 在线观看欧美一区 | 亚洲综合色视频在线观看 | 亚洲久在线 | 国产美女永久免费无遮挡 | 久久久免费少妇高潮毛片 | 国产午夜精品一区二区三区嫩草 | 国产一区二区三区在线观看免费 | 国产一区二区三区欧美 | 国产精品高潮呻吟久久aⅴ码 | 一区二区三区国产精品 | 欧美日韩视频在线第一区 | 国产精品久久久久久久久久久免费看 | 久草新在线 | 老司机午夜性大片 | 中文字幕日韩欧美一区二区三区 | 亚洲综合激情 | 久草在线在线精品观看 | 你懂的在线视频播放 | 欧美日韩在线免费观看 | 色天天综合 | 中日韩av | 午夜影视网 | 成人精品一区 | 亚洲一区二区三区在线观看免费 | 久久91 | 在线综合视频 | 国产午夜三级一区二区三 | 久久小视频 | 自拍视频国产 | 毛片视频网站 | 欧美在线高清 | 久久精品二区 | 国产亚洲精品久久yy50 | 午夜噜噜噜 | 国产一区二区久久久 | 精品亚洲一区二区三区 | 国产精品视频在线观看 | 日韩小视频在线 | 精品一区二区三区四区五区 | 91精品国产自产在线老师啪 | 久久com |