Get tab ui information from JTabbedPane in Java
Description
The following code shows how to get tab ui information from JTabbedPane.
Example
/*from w w w .j a v a2 s . com*/
import java.awt.BorderLayout;
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
public class Main {
public static void main(String args[]) {
JFrame frame = new JFrame("Tabbed Pane Sample");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab("java2s.com", new JButton("a"));
tabbedPane.addTab("java2s.com", new JButton("a"));
int count = tabbedPane.getTabCount();
for (int i = 0; i < count; i++) {
String label = tabbedPane.getTitleAt(i);
Icon icon = tabbedPane.getIconAt(i);
String tooltip = tabbedPane.getToolTipTextAt(i);
boolean enabled = tabbedPane.isEnabledAt(i);
int keycode = tabbedPane.getMnemonicAt(i);
Component comp = tabbedPane.getComponentAt(i);
}
frame.add(tabbedPane, BorderLayout.CENTER);
frame.setSize(400, 150);
frame.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »