卡布局Java应用程序不会显示任何内容

时间:2013-06-12 22:38:13

标签: java swing jframe jpanel cardlayout

我正在尝试制作基于卡片的应用程序。我一直在尝试按照教程等。这是我的代码。到目前为止它非常简单。窗口显示但内部的文本窗格不显示。

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package professorphysinstall;

/**
*
* @author Kyle
*/

//Imports
  import java.awt.CardLayout;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.JTextPane;

  public class ProfessorPhysInstall {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here
    //Variables
    JFrame mainframe = new JFrame();
    mainframe.setSize(500, 435);
    JPanel cards = new JPanel(new CardLayout());
    CardLayout cl = (CardLayout)(cards.getLayout());
    mainframe.setTitle("Future Retro Gaming Launcher");
    //Screen1
    JPanel screen1 = new JPanel();
    JTextPane TextPaneScreen1 = new JTextPane();
    TextPaneScreen1.setEditable(false);
    TextPaneScreen1.setBackground(new java.awt.Color(240, 240, 240));
    TextPaneScreen1.setText("Welcome to the install wizard  for Professor Phys!\n\nPlease agree to the following terms and click the next button to continue.");
    TextPaneScreen1.setSize(358, 48);
    TextPaneScreen1.setLocation(0, 0);
    screen1.add(TextPaneScreen1);
    mainframe.add(cards);
    mainframe.setVisible(true);
}
}

1 个答案:

答案 0 :(得分:3)

将包含JPanelJTextPane的{​​{1}}添加到screen1容器CardLayout

cards

除此之外:Java命名集合显示变量以小写字母开头,例如cards.add(screen1, "TextPane Card");