[英]a component for having layered characteristic in java app?
我有一个具有表单的Java应用程序,用户必须填写它,但是我想使用多层技术来填充大表单作为第三部分,单击“确定”,第一部分必须不可见,第二部分将可见,第三部分也保持不可见。
我必须使用jpanel
, jLayeredPane
或什么,以及如何使用netbeans?
您可能想看一下CardLayout ,这是一个教程, 如何使用CardLayout。
另一个选择是使用多个JDialogs。
...以及如何使用netbeans?
如果您打算使用GUI构建器,建议您学习Java而不是学习IDE :)
对于任何更高级的Swing应用程序,我强烈建议您使用Netbeans RCP。 您有一个现成的向导组件可以满足您的需求: http : //platform.netbeans.org/tutorials/nbm-wizard.html
试试看下面的代码:
import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;
public class Form
{
private static void createAndDisplayGUI()
{
JFrame frame = new JFrame("Form");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
final JPanel firstPanel = new JPanel();
firstPanel.setBackground(Color.DARK_GRAY);
JLabel label = new JLabel("I AM PANEL FIRST");
label.setForeground(Color.WHITE);
firstPanel.add(label);
final JPanel secondPanel = new JPanel();
secondPanel.setBackground(Color.YELLOW);
label = new JLabel("I AM PANEL SECOND");
label.setForeground(Color.BLACK);
secondPanel.add(label);
final JPanel thirdPanel = new JPanel();
thirdPanel.setBackground(Color.BLUE);
label = new JLabel("I AM PANEL THIRD");
label.setForeground(Color.WHITE);
thirdPanel.add(label);
JButton button = new JButton("NEXT");
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
if (firstPanel.isShowing())
{
firstPanel.setVisible(false);
secondPanel.setVisible(true);
}
else if (secondPanel.isShowing())
{
secondPanel.setVisible(false);
thirdPanel.setVisible(true);
}
}
});
mainPanel.add(firstPanel);
mainPanel.add(secondPanel);
mainPanel.add(thirdPanel);
mainPanel.add(button);
secondPanel.setVisible(false);
thirdPanel.setVisible(false);
frame.setContentPane(mainPanel);
frame.pack();
frame.setVisible(true);
}
public static void main(String... args)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
createAndDisplayGUI();
}
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.