首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将JTabbedPane添加到JTabbedPane错误

将JTabbedPane添加到JTabbedPane错误
EN

Stack Overflow用户
提问于 2013-03-04 07:08:54
回答 2查看 349关注 0票数 0

获取此错误:

Project.reportpane.addComponent(reportpane.java:69)线程“AWT 0”java.lang.NullPointerException中的异常

我无法将rptinvestment tabbedPane添加到面板表投资中

公共类报告窗格扩展JPanel {

代码语言:javascript
复制
JTabbedPane rpt;
JPanel tabcashflow;
JPanel tabinvestment;
JPanel tabexchangerates;
JTabbedPane rptinvestment;
JPanel tabofficial;
JPanel tabdem;
JPanel tabcommodities;

public reportpane() {

    rpt = new JTabbedPane();
    tabcashflow = new JPanel();
    tabinvestment = new JPanel();
    tabexchangerates = new JPanel();

    tabofficial = new JPanel();
    tabdem = new JPanel();
    tabcommodities = new JPanel();


    rpt.add("Cashflow", tabcashflow);
    rpt.add("Investement", tabinvestment);
    rpt.add("Exchange rates", tabexchangerates);
    rpt.setBackground(new Color(255, 255, 255));
    rpt.setFont(new Font("sansserif", Font.PLAIN, 14));
    rpt.setTabPlacement(javax.swing.JTabbedPane.TOP);
    rpt.setBorder(BorderFactory.createEmptyBorder());
    rpt.setSize(750, 500);


    rptinvestment = new JTabbedPane();
    rptinvestment.add("Official", tabofficial);
    rptinvestment.add("DEM", tabdem);
    rptinvestment.add("Commodities", tabcommodities);
    rptinvestment.setBackground(new Color(255, 255, 255));
    rptinvestment.setFont(new Font("sansserif", Font.PLAIN, 14));
    rptinvestment.setTabPlacement(JTabbedPane.TOP);
    rptinvestment.setBorder(BorderFactory.createEmptyBorder());
    rptinvestment.setSize(750, 500);

    addComponent(tabinvestment, rptinvestment, 0, 0, 675, 570);
    addComponent(this, rpt, 10, 10, 675, 570);



    this.setLayout(new BorderLayout());
    this.setBackground(Color.WHITE);
    this.setBorder(null);
    this.revalidate();
    this.repaint();

}

public void addComponent(Container container, Component c, int x, int y, int width, int height) {
    c.setBounds(x, y, width, height);
    container.add(c);
}

}

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-03-04 07:16:27

你从来没有初始化过表投资。您将其声明为实例变量,但从未在构造函数中初始化它。在某个时候,您需要调用JTabbedPane tabinvestment = new JTabbedPane()

票数 2
EN

Stack Overflow用户

发布于 2013-03-04 08:30:36

尝试使用被布局管理器重写的绝对定位添加组件。

JTabbedPane使用自己的布局逻辑,除非您真正创建自己的UI类,否则不能更改。

同样,您已经将框架布局管理器设置为BorderLayout,它将覆盖可能设置的任何定位值(以前设置为其他)。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15196309

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档