限制JPanel大小问题

时间:2016-09-17 08:20:48

标签: java swing jpanel japplet

美好的一天 -

我正在处理JApplets我有两个tabbedPanel。现在对于第一个tabbed我需要进一步将父JPanel分成两部分。为此,我创建了两个子面板,并使用JSplitPane类将它们分成两部分。

  1. eastPanel
  2. westPanel
  3. 窗口如下所示:

    enter image description here

    这是Resizeable因为我们可以看到最大化按钮已启用。我尝试设置此方法 setResizeable() ,但我认为它仅适用于JFRAME

    我尝试创建的所需UI如下:

    enter image description here

    我需要的是限制其大小,使其不再最大化,内容放在JPanel中。你能指导一下我应该遵循哪种方法来达到预期的效果吗?此外,来源如下:

        public class CreatePanel extends JPanel
     {
       private Vector athleteList;
       private JButton button1;
       private CountPanel cPanel;
       private TextField firstName;
       private TextArea textArea;
     //Constructor initializes components and organize them using certain layouts
     public CreatePanel(Vector athleteList, CountPanel cPanel)
      {
        this.athleteList = athleteList;
        this.cPanel = cPanel;
    
        //inner Jpanels to Split the parent panel
        JPanel eastPanel = new JPanel();
        JPanel westPanel = new JPanel();
    
        button1 = new JButton("Create an Athlete");
        textArea = new TextArea("No Athlete");
        textArea.setEditable(false);
    
        eastPanel.setBackground(Color.RED);
        westPanel.setBackground(Color.BLUE);
        eastPanel.add(button1);
        /* p1.add(firstName);
        p2.add(textArea);*/
    
        JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        sp.setResizeWeight(0.5);
        sp.setDividerSize(0);
        sp.add(eastPanel);
        sp.add(westPanel);
        //organize components here
        setLayout( new GridLayout(1, 2));    
    
    //    add(firstName,BorderLayout.WEST);
        add(sp);
    
    
      }
    
    
      //ButtonListener is a listener class that listens to
      //see if the button "Create an Athlete" is pushed.
      //When the event occurs, it adds an athlete using the information
      //entered by a user.
      //It also performs error checking.
      private class ButtonListener implements ActionListener
       {
        public void actionPerformed(ActionEvent event)
         {
    
             //TO BE COMPLETED
    
         } //end of actionPerformed method
      } //end of ButtonListener class
    
    } 
    

    DriveClass

    public class Test extends JApplet
     {
    
       private int APPLET_WIDTH = 500, APPLET_HEIGHT = 400;
    
       private JTabbedPane tPane;
       private CreatePanel createPanel;
       private CountPanel countPanel;
       private Vector athleteList;
    
       //The method init initializes the Applet with a Pane with two tabs
       public void init()
        {
         //list of athletes to be used in every panel
        athleteList = new Vector();
    
         //register panel uses the list of athletes
         countPanel = new CountPanel(athleteList);
    
         createPanel = new CreatePanel(athleteList, countPanel);
    
         //create a tabbed pane with two tabs
         tPane = new JTabbedPane();
         tPane.addTab("Athlete Creation", createPanel);
         tPane.addTab("Medal Count", countPanel);
         getContentPane().add(tPane);
         setSize (APPLET_WIDTH, APPLET_HEIGHT); //set Applet size
         setPreferredSize(new Dimension(APPLET_WIDTH, APPLET_HEIGHT));
         setMaximumSize(this.getPreferredSize());
         setMinimumSize(this.getPreferredSize());
        }
    }
    

    帮助将不胜感激。非常感谢

0 个答案:

没有答案