I am creating a tabbedpane
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"));
I get this error:
The method getComponentAt(Point) in the type Component is not applicable for the arguments (int)
How do I get hold of the LABEL I put on the selectedTab? I want to set the foreground on the label.
EDIT 1
I also get a null pointer error at runtime.
Component.getComponentAt
accepts a Point
object or two integers as int x, int y
, that it looks for child components at that location.
http://docs.oracle.com/javase/6/docs/api/java/awt/Component.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.