swing中的小知识

/*
 * 不使用java风格:JFrame.setDefaultLookAndFeelDecorated(true);
 * 设置窗口位置:this.setLocation(widthSize / 1024 * 850,heightSize / 768 * 100)
 * 窗口位于中央:this.setLocationRelativeTo(null)
 * 窗口大小是否可以拖动:this.setResizable(false)
 * 关闭风格:this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 * 设置窗体风格:
 * UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
 * SwingUtilities.updateComponentTreeUI(this);
 * 设置窗口图标:
 * Image image = Toolkit.getDefaultToolkit().createImage("images/001.png");
        this.setIconImage(image);
 * 设置窗口可见:this.setVisible(true)
 * 屏幕尺寸:Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
 * 字体样式大小:nameText.setFont(new Font(null, 0, 12));
 * 设置背景颜色:nameText.setBackground(Color.red)
 * 设置字体颜色:nameText.setForeground(Color.red)
 * 聚焦:pwdText.requestFocus();
 * 弹出框:JOptionPane.showMessageDialog(this, "请输入密码!", "提示信息", 2);
 * 图片处理:Image image = imageIcon.getImage();
        image = image.getScaledInstance(mainWidth, mainHeight,
                Image.SCALE_DEFAULT);
        imageIcon.setImage(image);
        imageLabel.setIcon(imageIcon);
 */

//关闭窗体退出虚拟机,其它窗体中不要这一句。否则关闭子窗体主窗体也关闭了
this.setDefaultCloseOperation(EXIT_ON_CLOSE);

//定义一个可滚动面板存放面板
JScrollPane jsp = new JScrollPane(photoPanel);
//加载图片面板
        jsp.setSize(mainWidth-10,mainHeight);
        //jsp.setBounds(0, 10, mainWidth-10, mainHeight);
        
        int lineNum = photosList.size();
        lineNum = lineNum % 10 == 0 ? lineNum / 10 + 1: lineNum / 10 + 2;
        
        //创建布局管理器
        GridLayout panelLayout = new GridLayout(lineNum,10);
        
        //设置列距
        panelLayout.setHgap((mainWidth-10 - 60 * 10) / 10);
        
        //设置行距
        panelLayout.setVgap(20);
        photoPanel.setLayout(panelLayout);
        photoPanel.setBackground(Color.gray);
        
        //将图片的标签放入面板中
        loadPhotoLabel();
        
        this.add(jsp);


/**
 * 弹出的对话框
 * public static int showConfirmDialog(Component parentComponent,
                                    Object message,
                                    String title,
                                    int optionType)
                             throws HeadlessException调出一个由 optionType 参数确定其中选项数的对话框。
参数:
parentComponent - 确定在其中显示对话框的 Frame;如果为 null 或者 parentComponent 不具有 Frame,则使用默认的 Frame
message - 要显示的 Object
title - 对话框的标题字符串
optionType - 指定可用于对话框的选项的 int:YES_NO_OPTION、YES_NO_CANCEL_OPTION 或 OK_CANCEL_OPTION
返回:指示用户所选选项的 int
 *释放资源:this.dispose();
 */
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值