我怎样才能获得JtabbedPane中的jPanel

时间:2014-06-12 08:49:12

标签: java swing jpanel jtabbedpane

我在java中开发了一个图像编辑器,我在JTabbedPane中插入了一个JPanel,创建了一个带有标签的JTabbedPane,这些标签显示我要应用于图像的图像过滤器, 我不知道如何获得TabbedPane的内部JPanel来决定选择女巫过滤器, 因为当我做的时候#34; jTabbedPane1.getSelectedComponent(); "我只能获得一个不是JComponent的组件..

任何人都知道的事情,对不起我的英语谢谢......

这是我的代码的一部分:

package javaapplication22;

import javax.swing.JPanel;

/**
 *
 * @author iDoc
 */
public abstract class FilterTab extends JPanel {

    public FilterTab() {

    }

    protected void ApplyFilter() {

    }

    protected void ResetFilter() {

    }

}

public class InvertFilterTab extends FilterTab {

    private InvertFilter filter;

    public InvertFilterTab ()
    {
        filter = new InvertFilter();
    }

    /**
     *
     * @param originalImage
     * @param modifiedImage
     */
    public void ApplyFilter(BufferedImage originalImage, BufferedImage modifiedImage) {
        modifiedImage = filter.filter(originalImage, modifiedImage);
    }

    @Override
    public void ResetFilter() {

    }

}

private void button1ActionPerformed(java.awt.event.ActionEvent evt) {                                        

    BufferedImage originalImage = jOriginalPanel.getImage();
  //  BufferedImage modifiedImage = new BufferedImage(
    //        originalImage.getWidth(), originalImage.getHeight(), 
      //      BufferedImage.TYPE_INT_ARGB);
    //modifiedImage = 

    FilterTab ft = jTabbedPane1.getSelectedComponent();   <--- the problem is here

            filter.filter(originalImage, modifiedImage);

    jModifiedPanel.changeImage(modifiedImage);
    jModifiedPanel.repaint();

1 个答案:

答案 0 :(得分:2)

简单地投射结果......

FilterTab tab = (FilterTab)jTabbedPane1.getSelectedComponent();

请注意,JPanel来自JComponent,其范围从Container延伸,从Component延伸