Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中的Scrollabe JFrame_Java_User Interface_Scrollbar_Jframe - Fatal编程技术网

Java中的Scrollabe JFrame

Java中的Scrollabe JFrame,java,user-interface,scrollbar,jframe,Java,User Interface,Scrollbar,Jframe,我有一个带有“驱动程序GUI”java文件的程序,可以创建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

我有一个带有“驱动程序GUI”java文件的程序,可以创建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、JButtons和JTextfields

资源代码的一个片段如下所示:

    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和setResizeable的维度设置为false(.setResizeable(false));)之后,如何使JFrame垂直滚动

您可以使用JScrollPane来实现这一点,并将其视图端口设置为您的面板。

我是否在“驱动程序类”中使用JScrollPane。JScrollPane代码是什么?我需要什么导入语句?我应该把它放在哪里?这里有一个简单的例子。使用GpaCalc实例,而不是示例中的列表。
frame.setContentPane(new JScrollPane(new GpaCalc()));