我有一個創建JFrame及其規範的「Driver GUI」java文件的程序。Java中的Scrollabe JFrame
public static void main(String[] args)
{
/*Create a frame (outside box) and write what text
will be displayed as the frame title*/
JFrame frame = new JFrame("PHILIP MCQUITTY");
//give frame a size
frame.setSize(520,375);
//set location on the computer screen will frame appear
frame.setLocation(400, 166);
//use this so when you press X in corner, frame will close
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add your panel to the frame. name must match Panel class name
frame.setContentPane(new GpaCalc());
//frame.setResizable(false);
// always include
frame.setVisible(true);
}
該GUI調用.setContentPane方法,並將其連接到我創建了我所有的JLables,Jbutton將和JTextField的我的資源類。
資源代碼片段看起來是這樣的:
public class GpaCalc extends JPanel
{
private JLabel GPALabel, c1, c2, c3, c4, c5, c6, c7, g1, g2, g3, g4, g5, g6, g7;
private JTextField Class1, Class2, Class3, Class4, Class5, Class6, Class7, Grade1, Grade2, Grade3, Grade4, Grade5, Grade6, Grade7;
private double GPA1, GPA2, GPA3, GPA4, GPA5, GPA6, GPA7, GPA, BigDec;
public GpaCalc()
{
setLayout (new FlowLayout());
JPanel panel=new JPanel();
//Class Labels
GPALabel = new JLabel ("0.00000000000000");
GPALabel.setFont (new Font("Times New Roman", Font.BOLD, 60));
GPALabel.setForeground (Color.red);
所以我的問題是,我該如何讓我的JFrame垂直滾動後,我把我的JFrame和的setResizable假尺寸(.setResizable(假));)?
在我的「驅動程序類」中使用JScrollPane嗎?什麼是JScrollPane代碼?我需要什麼進口聲明?我在哪裏放? – 2011-04-02 03:37:12
下面是一個簡單的例子。 http://www.java2s.com/Code/Java/Swing-JFC/AsimpleJScrollPaneforaJListcomponent.htm 而不是示例中的列表,請使用您的GpaCalc實例。 – 2011-04-02 03:38:58