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

  • 相关阅读:
    The Instruments Workflow
    About Instruments
    视频播放插件Video.js
    各大三方API
    Xib、AutoLayout等使用心得
    克隆示例
    接口类型的多重继承
    高级着色语言简介
    DirectX Box
    Direct3D初始化
  • 原文地址:https://www.cnblogs.com/aaroncnblogs/p/8657273.html
Copyright © 2011-2022 走看看