jinlin
2025-03-22 b20c16dd6c9fd19a44afe2b082c2fa5ff8945aaa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.example.client.utils;
 
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
 
/**
 * 旋转等待的dialog
 */
public class WaitUtil extends JDialog {
    private static final long serialVersionUID = 6987303361741568128L;
    private final JPanel contentPanel = new JPanel();
 
 
    /**
     * Create the dialog.
     */
    public WaitUtil(String imgPath,String text) {
        setBounds(0, 0, 200, 100);
        getContentPane().setLayout(new BorderLayout());
        contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        getContentPane().add(contentPanel, BorderLayout.CENTER);
        contentPanel.setLayout(null);
        {
            JLabel lblLoading = new JLabel(text);
            lblLoading.setForeground(Color.DARK_GRAY);
            lblLoading.setOpaque(false);
            lblLoading.setIcon(new ImageIcon(imgPath + "/loading.gif"));
            lblLoading.setFont(new Font("宋体", Font.PLAIN, 15));
            lblLoading.setBounds(0, 0, 200, 100);
            contentPanel.add(lblLoading);
        }
 
        setModalityType(ModalityType.TOOLKIT_MODAL);    //置顶显示
        setUndecorated(true);   //禁用或启用此窗体的装饰(true:禁用;false:启用)
        setLocationRelativeTo(null);    //设置窗口相对于指定组件的位置(null表示置于屏幕的中央)
    }
}