zoukankan      html  css  js  c++  java
  • Swing

    创建窗口

    //1. Create the frame.
    JFrame frame = new JFrame("FrameDemo");
    
    //2. Optional: What happens when the frame closes?
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    //3. Create components and put them in the frame.
    //...create emptyLabel...
    frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
    
    //4. Size the frame.
    frame.pack();
    
    //5. Show it.
    frame.setVisible(true);

    通过getContentPane获取到的顶层容器,返回的是Container,可以强制转化为JComponent使用,默认布局为BorderLayout

    更换布局

    //Create a panel and add components to it.
    JPanel contentPane = new JPanel(new BorderLayout());
    contentPane.setBorder(someBorder);
    contentPane.add(someComponent, BorderLayout.CENTER);
    contentPane.add(anotherComponent, BorderLayout.PAGE_END);
    topLevelContainer.setContentPane(contentPane);

    JPanel的默认布局为FlowLayout

  • 相关阅读:
    指针理解
    http和https区别
    js 日历控件
    Linux 目录详解!(转)
    互换位置输出
    晨时跌荡起伏的心情
    c++冒泡排序
    游标使用
    防止Sql注入
    ssl加密原理
  • 原文地址:https://www.cnblogs.com/aaroncnblogs/p/8657273.html
Copyright © 2011-2022 走看看