簡體   English   中英

如何在運行時更改JTabbedpane組件的屬性?

[英]How can I change properties of a JTabbedpane component at run time?

我正在創建一個選項卡式窗格

tabs= new JTabbedPane();
tabs.addChangeListener(new ChangeListener() {
    @Override
    public void stateChanged(ChangeEvent e) {
          JTabbedPane sourceTabbedPane = (JTabbedPane) e.getSource();
          int index = sourceTabbedPane.getSelectedIndex();
          sourceTabbedPane.getTabComponentAt(index).getComponentAt(0).setForeground(Color.RED);

});

tabs.setTabComponentAt(0, new JLabel("tab1"));
tabs.setTabComponentAt(0, new JLabel("tab2"));

我收到此錯誤:

Component類型的getComponentAt(Point)方法不適用於參數(int)

如何獲得放置在selectedTab上的標簽? 我想在標簽上設置前景。

EDIT 1

在運行時,我還會收到一個空指針錯誤。

Component.getComponentAt接受一個Point對象或兩個整數,如int x, int y ,它在該位置查找子組件。

http://docs.oracle.com/javase/6/docs/api/java/awt/Component.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM