【问题标题】:JFrame and different "pages" of contentJFrame 和不同的内容“页面”
【发布时间】:2013-06-22 14:42:15
【问题描述】:

我对 Java 很陌生,现在我正在玩 GUI。我现在有一个JFrame - 我们称之为page1 - 有一些内容(文本、图像等)。所以我想做的是创建几个这样的具有不同内容的“页面”,并且能够在我的程序中在这些页面之间切换。

所以我的问题是,最好的方法是什么?假设我想创建一个带有不同图像和文本的 page2,我应该注意什么才能做到这一点?

我希望这是可以理解的。我只需要被推向正确的方向,这样我就知道要研究什么了。

【问题讨论】:

  • 寻找CardLayout - 如果我理解你的问题,你就会理解我的评论。
  • 你的问题不清楚,但既然你提到了页面,我猜你想创建一个向导。查看 Oracle 的向导指南。 oracle.com/technetwork/articles/javase/wizard-136789.html
  • this CardLayout 的例子(靠近答案的底部)

标签: java swing user-interface jframe


【解决方案1】:

您可能想使用 CardLayout 。这里有教程how to use CardLayout

例子:

//Where instance variables are declared:
JPanel cards;
final static String BUTTONPANEL = "Card with JButtons";
final static String TEXTPANEL = "Card with JTextField";

//Where the components controlled by the CardLayout are initialized:
//Create the "cards".
JPanel card1 = new JPanel();
...
JPanel card2 = new JPanel();
...

//Create the panel that contains the "cards".
cards = new JPanel(new CardLayout());
cards.add(card1, BUTTONPANEL);
cards.add(card2, TEXTPANEL);

【讨论】:

    猜你喜欢
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多