從你的描述,似乎UI要求是這樣的:
顯示GUI比自然大小
GUI顯示 '大事情' 大一點(綠色)帶頂部工具欄
GUI顯示浮動工具欄的「大事情」(綠色)
import java.awt.*;
import java.awt.event.ActionEvent;
import javax.swing.*;
public class ConsoleGUI {
JPanel ui;
String[] cards = {"Console", "Big Component"};
CardLayout cardLayout;
JPanel cardPanel;
public ConsoleGUI() {
initUI();
}
public void initUI() {
if (ui == null) {
ui = new JPanel(new BorderLayout());
JToolBar tools = new JToolBar();
ui.add(tools, BorderLayout.PAGE_START);
tools.add(new JButton("Open"));
tools.add(new JButton("Save"));
tools.addSeparator();
tools.add(new CardFlipperAction(cards[0]));
tools.add(new CardFlipperAction(cards[1]));
cardLayout = new CardLayout();
cardPanel = new JPanel(cardLayout);
ui.add(cardPanel, BorderLayout.CENTER);
JTextArea console = new JTextArea(3, 40);
JPanel consoleContainer = new JPanel(new GridBagLayout());
consoleContainer.add(new JScrollPane(console));
cardPanel.add(cards[0], consoleContainer);
JPanel bigThing = new JPanel(new GridLayout());
bigThing.setBackground(Color.GREEN.darker());
cardPanel.add(cards[1], bigThing);
}
}
public JComponent getUI() {
return ui;
}
class CardFlipperAction extends AbstractAction {
CardFlipperAction(String name) {
super(name);
}
@Override
public void actionPerformed(ActionEvent e) {
cardLayout.show(cardPanel, e.getActionCommand());
}
}
public static void main(String[] args) {
Runnable r = new Runnable() {
@Override
public void run() {
ConsoleGUI cg = new ConsoleGUI();
JFrame f = new JFrame("Console GUI");
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setContentPane(cg.getUI());
f.pack();
f.setMinimumSize(f.getSize());
f.setLocationByPlatform(true);
f.setVisible(true);
}
};
SwingUtilities.invokeLater(r);
}
}
*「這個新開業面板必須涵蓋所有Jframe的空間,另外這個過程必須是前進和後退」 *什麼組件將用戶移回原始屏幕?爲什麼不把該組件放在「必須覆蓋所有屏幕」組件? – 2014-09-27 07:20:00
答案是:*它取決於* - 正如此,將其標記爲「太寬」 – vaxquis 2014-09-27 07:22:12
@AndrewThompson更少?建立Windows的複雜性或簡單的後退導航,您的選擇先生?示例:選項菜單,文件菜單或任何其他定製屏幕。我很欣賞你的意見。非常感謝。 – iColdBeZero 2014-09-27 07:24:45