欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

idea插件開發(fā)之彈出框的示例代碼

 更新時間:2020年12月16日 10:57:20   作者:EcksYang-1128  
這篇文章主要介紹了idea插件開發(fā)之彈出框的示例代碼,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

前言

IntelliJ平臺的用戶界面廣泛使用彈出窗口,即沒有chrome(顯式關閉按鈕)的半模式窗口,在焦點丟失時自動消失。在插件中使用這些控件可以確保插件和IDE其他部分之間的用戶體驗一致。
彈出窗口可以選擇性地顯示標題,也可以移動和調(diào)整大小(并支持記住它們的大?。?,并且可以嵌套(當選擇一個項目時顯示另一個彈出窗口)。

一、JBPopupFactory

JBPopupFactory 是idea 提供給用戶自定義窗口的接口,比較常見的方法如下

  • createComponentPopupBuilder() 允許您在彈出窗口中顯示任何Swing組件。
  • createPopupChooserBuilder() 創(chuàng)建一個多選/單選框
  • createConfirmation() 創(chuàng)建一個確認框
  • createActionGroupPopup() 創(chuàng)建一個顯示方法組的窗口,選中會執(zhí)行方法。

創(chuàng)建彈出窗口后,需要通過調(diào)用show() 方法之一來顯示它。您可以通過調(diào)用showInBestPositionFor() 讓IntelliJ平臺根據(jù)上下文自動選擇位置,或者通過showUnderneathOf() 和ShowInCenter() 等方法顯式指定位置。

show() 方法立即返回,不等待彈出窗口關閉。

如果需要在彈出窗口關閉時執(zhí)行某些操作,可以使用addListener() 方法將偵聽器附加到它,然后重寫彈出試的方法,例如onChosen(),或在彈出窗口中將事件處理程序附加到您自己的組件。

二、demo

 1.showInBestPositionFor

Shows the popup in the position most appropriate for the specified data context.
在最適合指定數(shù)據(jù)上下文的位置顯示彈出窗口。

acaction 定義按鈕功能

public class TextBoxes extends AnAction {

 public TextBoxes() {
  super("MYSQL_COLUMN_ADD_PRO");
 }


 @Override
 public void actionPerformed(@NotNull AnActionEvent event) {
   // 獲取 JBPopupFactory
  JBPopupFactory instance = JBPopupFactory.getInstance();
  
  // 創(chuàng)建需要執(zhí)行的任務
  Runnable runnable = new Runnable() {
   @Override
   public void run() {
    Messages.showMessageDialog("aaa", "hello", Messages.getInformationIcon());
   }
  };
  ListPopup popup = instance.createConfirmation("hello", runnable, 1);
  popup.showInBestPositionFor(event.getDataContext());
 }
}

plugins.xml

<idea-plugin>
 <id>org.example.myPlugins</id>
 <name>MyPlugin</name>
 <vendor email="1585946147@qq.com" url="http://www.baidu.com">lieying</vendor>
 <description>first test plugin</description>
 <extensions defaultExtensionNs="com.intellij">
  <!-- Add your extensions here -->
 </extensions>
 <actions>
  <!-- Add your actions here -->
  <group id="MyPlugin.SampleMenu" text="_Sample Menu" description="Sample menu">
   <add-to-group group-id="MainMenu" anchor="last" />
   <action id="Myplugin.Textboxes" class="com.hunt.plugin.TextBoxes" text="Text _Boxes" description="A test menu item">
    <keyboard-shortcut keymap="$default" first-keystroke="ctrl alt Z" />
   </action>
  </group>
 </actions>
</idea-plugin>

實際效果

在這里插入圖片描述

2.show()

Shows the popup at the specified point.
顯示指定點的彈出窗口。

@Override
 public void actionPerformed(@NotNull AnActionEvent event) {
  // 獲取 JBPopupFactory
  JBPopupFactory instance = JBPopupFactory.getInstance();

  // 創(chuàng)建需要執(zhí)行的任務
  Runnable runnable = new Runnable() {
   @Override
   public void run() {
    Messages.showMessageDialog("aaa", "hello", Messages.getInformationIcon());
   }
  };
  ListPopup popup = instance.createConfirmation("hello", runnable, 1);

  // 固定指定一個點顯示
  Point point = new Point(200,300);
  RelativePoint relativePoint = new RelativePoint(point);
  popup.show(relativePoint);
 }

效果如下

在這里插入圖片描述

3.showUnderneathOf()

Shows the popup at the bottom left corner of the specified component.
顯示指定組件左下角的彈出窗口。

@Override
 public void actionPerformed(@NotNull AnActionEvent event) {
  // 獲取 JBPopupFactory
  JBPopupFactory instance = JBPopupFactory.getInstance();

  // 創(chuàng)建需要執(zhí)行的任務
  Runnable runnable = new Runnable() {
   @Override
   public void run() {
    Messages.showMessageDialog("aaa", "hello", Messages.getInformationIcon());
   }
  };
  ListPopup popup = instance.createConfirmation("hello", runnable, 1);

  // 獲取焦點的組件
  Component component = event.getDataContext().getData(PlatformDataKeys.CONTEXT_COMPONENT);
  // 組件下方顯示 popup
  popup.showUnderneathOf(component); 
 }

event.getDataContext().getData(PlatformDataKeys.CONTEXT_COMPONENT); 會返回獲取焦點的組件
比如

在這里插入圖片描述

4.showInFocusCenter

Shows the popups in the center of currently focused component
在獲取焦點組件的中間彈出popup

@Override
 public void actionPerformed(@NotNull AnActionEvent event) {
  // 獲取 JBPopupFactory
  JBPopupFactory instance = JBPopupFactory.getInstance();

  // 創(chuàng)建需要執(zhí)行的任務
  Runnable runnable = new Runnable() {
   @Override
   public void run() {
    Messages.showMessageDialog("aaa", "hello", Messages.getInformationIcon());
   }
  };
  ListPopup popup = instance.createConfirmation("hello", runnable, 1);

  popup.showInFocusCenter();
 }

在這里插入圖片描述

到此這篇關于idea插件開發(fā)之彈出框的示例代碼的文章就介紹到這了,更多相關idea彈出框內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Java對象數(shù)組的添加、刪除和遍歷代碼示例

    Java對象數(shù)組的添加、刪除和遍歷代碼示例

    在Java編程中,我們經(jīng)常需要對數(shù)據(jù)結構進行遍歷操作,并根據(jù)業(yè)務需求刪除部分元素,這篇文章主要給大家介紹了關于Java對象數(shù)組的添加、刪除和遍歷的相關資料,需要的朋友可以參考下
    2024-04-04
  • Mybatis使用JSONObject接收數(shù)據(jù)庫查詢的方法

    Mybatis使用JSONObject接收數(shù)據(jù)庫查詢的方法

    這篇文章主要介紹了Mybatis使用JSONObject接收數(shù)據(jù)庫查詢,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-12-12
  • Java監(jiān)聽器的作用及用法代碼示例

    Java監(jiān)聽器的作用及用法代碼示例

    這篇文章主要介紹了Java監(jiān)聽器的作用及用法代碼示例,具有一定參考價值,需要的朋友可以了解下。
    2017-11-11
  • Java設計模式--適配器模式詳解

    Java設計模式--適配器模式詳解

    這篇文章主要介紹了java設計模式之適配器模式Adapter的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • java實現(xiàn)表格數(shù)據(jù)的存儲

    java實現(xiàn)表格數(shù)據(jù)的存儲

    這篇文章主要為大家詳細介紹了java實現(xiàn)表格數(shù)據(jù)的存儲,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-04-04
  • SpringBoot實現(xiàn)阿里云快遞物流查詢的示例代碼

    SpringBoot實現(xiàn)阿里云快遞物流查詢的示例代碼

    本文將基于springboot實現(xiàn)快遞物流查詢,物流信息的獲取通過阿里云第三方實現(xiàn),具有一定的參考價值,感興趣的可以了解一下
    2021-10-10
  • 分布式Netty源碼分析概覽

    分布式Netty源碼分析概覽

    這篇文章主要為大家介紹了分布式Netty源碼分析概覽,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-03-03
  • JVM常見垃圾收集器學習指南

    JVM常見垃圾收集器學習指南

    這篇文章主要為大家介紹了JVM常見垃圾收集器學習指南,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-06-06
  • Stream中的Peek操作代碼

    Stream中的Peek操作代碼

    這篇文章主要介紹了Stream中的Peek操作,本文通過示例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-09-09
  • 一文帶你深入理解Java?AbstractQueuedSynchronizer

    一文帶你深入理解Java?AbstractQueuedSynchronizer

    在并發(fā)編程中,鎖是一種保證線程安全的方式,這篇文章主要為大家介紹了AbstractQueuedSynchronizer(AQS)的數(shù)據(jù)結構及實現(xiàn)原理,感興趣的小伙伴可以了解一下
    2023-07-07

最新評論