【发布时间】:2014-11-03 03:28:25
【问题描述】:
我无法将此 JPanel 添加到窗格的中心块中。本质上,这个主窗口是一个 BorderLayout,其中心有 centerPanel,而西和东块将是单独的 BorderLayouts。我已经用谷歌搜索了这个问题,并查看了我教授的示例代码以及 stackoverflow 上的示例代码,但我在我的代码中找不到问题。
我在 Eclipse 中完成所有编码,因此我使用集成的 AppletViewer。唯一出现的是一个空的灰色框,我希望在其中看到包括 JLabels 和 JTextAreas 的 centerPanel。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Lab7 extends JApplet implements ItemListener, ActionListener{
//variables
private JLabel currentOrder, total;
private JTextArea descTop, currentOrderTA, totalTA;
private JRadioButton sizeSmall, sizeMedium, sizeLarge, typeDeep, typePan, typeHand;
private JCheckBox pepperoni, bacon, extra_cheese, mushroom, pepper, sausage, tomato, olive;
private JButton orderButton, resetButton;
private ButtonGroup sizeBG, typeBG;
private BorderLayout borderLayoutMain, borderLayoutWest, borderLayoutEast;
private JPanel westPanel, centerPanel, eastPanel;
public void init(){
Container pane = getContentPane();
pane.setLayout(borderLayoutMain);
//borderLayoutMain centerPanel
centerPanel = new JPanel();
centerPanel.setLayout(null);
currentOrder.setSize(200, 25);
currentOrder.setLocation(100, 25);
currentOrderTA.setSize(600, 400);
currentOrderTA.setLocation(100, 50);
currentOrderTA.setEditable(false);
total.setSize(200, 25);
totalTA.setLocation(100, 450);
totalTA.setEditable(false);
orderButton.setSize(100, 50);
orderButton.setLocation(100, 500);
resetButton.setSize(100, 50);
resetButton.setLocation(400, 500);
centerPanel.add(currentOrder);
centerPanel.add(currentOrderTA);
centerPanel.add(total);
centerPanel.add(totalTA);
centerPanel.add(orderButton);
centerPanel.add(resetButton);
pane.add(centerPanel, BorderLayout.CENTER);
}
【问题讨论】:
标签: java jpanel japplet border-layout