美好的一天 -
我正在处理JApplets
我有两个tabbedPanel
。现在对于第一个tabbed
我需要进一步将父JPanel
分成两部分。为此,我创建了两个子面板,并使用JSplitPane
类将它们分成两部分。
窗口如下所示:
这是Resizeable
因为我们可以看到最大化按钮已启用。我尝试设置此方法 setResizeable()
,但我认为它仅适用于JFRAME
。
我尝试创建的所需UI如下:
我需要的是限制其大小,使其不再最大化,内容放在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());
}
}
帮助将不胜感激。非常感谢