码迷,mamicode.com
首页 > 其他好文 > 详细

e559. 创建窗口

时间:2018-09-06 11:02:03      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:window   level   done   contents   you   show   jtextarea   order   ted   

A frame is a component container that displays its contents in a top-level window with a title bar and buttons to resize, iconify, maximize, and close the frame.

Unlike most Swing containers, adding a component to a frame is not done with the JFrame.add() method. This is because the frame holds several panes and it is necessary to specify a particular pane to which to add the component. The pane that holds child components is called the content pane. This example adds a text area to the content pane of a frame.

See also e559 创建窗口.

    // Create the frame
    String title = "Frame Title";
    JFrame frame = new JFrame(title);
    
    // Create a component to add to the frame
    JComponent comp = new JTextArea();
    
    // Add the component to the frame‘s content pane;
    // by default, the content pane has a border layout
    frame.getContentPane().add(comp, BorderLayout.CENTER);
    
    // Show the frame
    int width = 300;
    int height = 300;
    frame.setSize(width, height);
    frame.setVisible(true);

 

Related Examples

e559. 创建窗口

标签:window   level   done   contents   you   show   jtextarea   order   ted   

原文地址:https://www.cnblogs.com/borter/p/9596112.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!