且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将JScrollPane添加到JFrame

更新时间:2023-12-05 18:42:10

默认情况下,JFrame具有Borderlayout. BorderLayout有五个标志.当您不指定任何标志时,它将把您的组件添加到带有中心标志的框架中.如果没有为组件指定其他标志,则中心标志为组件添加了所有带有中心标志的空间.有关边框布局的更多信息,请访问以下链接: http://docs.oracle.com/javase/tutorial/uiswing/layout /border.html

By Default, JFrame has Borderlayout. BorderLayout have five flags. When you will not specify any flag, It will add you component to frame with center flag. Center flag give all space to component which is added with center flag, if no other flag is specified with component. for more information on border layout, visit following link: http://docs.oracle.com/javase/tutorial/uiswing/layout/border.html

您可以使用以下语句添加两者:

You can add both by using following statement:

JFrame frame = new JFrame();

frame.add(new JPanel(), BorderLayout.NORTH);

frame.add(new JScrollpane(), BorderLayout.CENTER);