Skip to content

IDEA的右下角通知以及对话框和表单控件的开发。

1.通知

xml
<extensions defaultExtensionNs="com.intellij">
    <notificationGroup id="MyFirstNotify" displayType="BALLOON"/>
</extensions>
java
 NotificationGroupManager.getInstance().getNotificationGroup("MyFirstNotify")
                .createNotification("测试", NotificationType.INFORMATION)
                .notify(e.getProject());

2.对话框

第一步:创建提示框

java
public class SampleDialogWrapper extends DialogWrapper {
    protected SampleDialogWrapper(String title) {
        super(true);
        setTitle(title); // 标题
        init();
    }

    @Override
    protected @Nullable JComponent createCenterPanel() {
        JPanel panel = new JPanel();
        JLabel jLabel = new JLabel("我是内容部分");
        panel.add(jLabel);
        return panel;
    }
}

第二步:显示

java
SampleDialogWrapper dialogWrapper = new SampleDialogWrapper("启动提示");
dialogWrapper.show();

第三步:重写底部按钮

java
@Override
protected JComponent createSouthPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    JButton btn = new JButton("点击确定"); // 按钮名称
    btn.addActionListener(e -> {
        // TODO 按钮点击后的事件
    });
    panel.add(btn);
    return panel;
}

3.表单控件

输入框

java
// 核心代码
EditorTextField tfContent = new EditorTextField();
tfContent.setPlaceholder("请输入笔记内容"); // 提示信息
tfContent.setPreferredSize(new Dimension(200,100)); // 输入框大小
// 示例
protected @Nullable JComponent createCenterPanel() {
    JPanel panel = new JPanel(new BorderLayout()); // 区域布局,分为东南西北
    tfTitle = new EditorTextField("笔记标题");
    tfContent = new EditorTextField();
    tfContent.setPlaceholder("请输入笔记内容"); // 提示信息
    tfContent.setPreferredSize(new Dimension(200,100)); // 输入框大小
    panel.add(tfTitle,BorderLayout.NORTH);// 将空间位于北方(上方)
    panel.add(tfContent,BorderLayout.CENTER);// 位于中间
    return panel;
}