我在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();
答案 0 :(得分:2)
简单地投射结果......
FilterTab tab = (FilterTab)jTabbedPane1.getSelectedComponent();
请注意,JPanel
来自JComponent
,其范围从Container
延伸,从Component
延伸