2013-06-12 46 views
0

我正在嘗試製作基於卡的應用程序。我一直在試圖遵循教程等。這是我的代碼。迄今爲止它非常簡單。窗口顯示出來,但裏面的textpane沒有。卡布局Java應用程序不會顯示任何內容

/* 
* 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); 
} 
} 

回答

3

添加含有JTextPanescreen1,到CardLayout容器cardsJPanel

cards.add(screen1, "TextPane Card"); 

旁白:Java命名concentions顯示,變量以小寫字母textPaneScreen1

+0

哦,對了。非常感謝! – Kyle

+0

任何機會,你會知道如何添加一個邊界,但有一點點的空間?它試圖將邊距改爲3,但這根本沒有移動邊界。 – Kyle

+0

你讓我很少去這裏。什麼類型的邊框?你嘗試了什麼,什麼沒有奏效。可能作爲一個新問題更好 – Reimeus

相關問題