Oracle has a helpful tutorial, Creating a GUI With Swing. Skip the Learning Swing with the NetBeans IDE section.
I modified your code to create the following GUI.
All Swing applications must start with a call to the SwingUtilitiesinvokeLater method. This method ensures that the Swing components are created and executed on the Event Dispatch Thread.
I separated the creation of the JFrame and the JPanels. You size each of the JPanels, ideally by filling each JPanel with Swing components. You pack the JFrame, letting it take the size of the JPanels. Pay close attention to the Laying Out Components Within a Container section.
发布评论
评论(1)
Oracle有一个有用的教程,创建带有swing 的GUI。使用Netbeans IDE部分跳过学习秋千。
我修改了您的代码以创建以下GUI。
所有摆动应用程序必须以
swingutilities
InvokeLater
方法开始调用。 This method ensures that the Swing components are created and executed on the Event Dispatch Thread 。我分开了
jframe
和jpanels
的创建。您可以通过填充每个jpanel的摇摆组件来大小jpanels
。您打包jframe
,让它采用jpanels
的大小。请密切注意在容器中放置组件部分。这是完整的可运行代码。
Oracle has a helpful tutorial, Creating a GUI With Swing. Skip the Learning Swing with the NetBeans IDE section.
I modified your code to create the following GUI.
All Swing applications must start with a call to the
SwingUtilities
invokeLater
method. This method ensures that the Swing components are created and executed on the Event Dispatch Thread.I separated the creation of the
JFrame
and theJPanels
. You size each of theJPanels
, ideally by filling each JPanel with Swing components. You pack theJFrame
, letting it take the size of theJPanels
. Pay close attention to the Laying Out Components Within a Container section.Here's the complete runnable code.