下面列出了javax.swing.JTabbedPane#getTitleAt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static Object getValue(String key) {
JComponent component = components.get(key);
if (component == null)
return inits.get(key);
if (component instanceof JTextField)
return ((JTextField) component).getText();
else if (component instanceof JComboBox)
return (String) ((JComboBox) component).getSelectedItem();
else if (component instanceof JCheckBox)
return ((JCheckBox) component).isSelected() ? "true" : "false";
else if (component instanceof JLabel)
return ((JLabel) component).getText();
else if (component instanceof SpinnerRangeDouble)
return new Double(((SpinnerRangeDouble) component).get());
else if (component instanceof SpinnerRangeInteger)
return new Integer(((SpinnerRangeInteger) component).get());
else if (component instanceof JTabbedPane) {
JTabbedPane tab = (JTabbedPane) component;
return tab.getTitleAt(tab.getSelectedIndex());
}
return inits.get(key);
}
private void deleteTestData(Object source) {
JTabbedPane tab = (JTabbedPane) source;
TestDataTablePanel panel = getSelectedData();
if (!panel.isGlobalData) {
int index = tab.getSelectedIndex();
String name = tab.getTitleAt(index);
int option = JOptionPane.showConfirmDialog(null, "Are you sure want to delete the TestData [" + name + "]", "Delete TestData", JOptionPane.YES_NO_OPTION);
if (option == JOptionPane.YES_OPTION) {
Boolean flag = testDesign.getProject().getTestData()
.getTestDataFor(envTab.getTitleAt(envTab.getSelectedIndex()))
.deleteTestData(name);
if (flag) {
tab.setSelectedIndex(index - 1);
tab.removeTabAt(index);
} else {
Notification.show("Couldn't Delete Testdata - '" + name + "'");
}
}
}
}
@Override
public void componentAdded(ContainerEvent e) {
JTabbedPane tp = (JTabbedPane) e.getContainer();
Component child = e.getChild();
if (child instanceof UIResource) {
return;
}
int index = tp.indexOfComponent(child);
String title = tp.getTitleAt(index);
boolean isHTML = BasicHTML.isHTMLString(title);
if (isHTML) {
if (htmlViews == null) { // Initialize vector
htmlViews = createHTMLVector();
}
else { // Vector already exists
View v = BasicHTML.createHTMLView(tp, title);
htmlViews.insertElementAt(v, index);
}
}
else { // Not HTML
if (htmlViews != null) { // Add placeholder
htmlViews.insertElementAt(null, index);
} // else nada!
}
}
public void menuSelected(MenuEvent e) {
TabsMenu.this.removeAll();
ExploreNodeAction exploreAction = new ExploreNodeAction(cliGuiCtx);
JMenuItem exploreSelectedNode = new JMenuItem(exploreAction);
exploreSelectedNode.setMnemonic(KeyEvent.VK_E);
if ((exploreAction.getSelectedNode() == null) || exploreAction.getSelectedNode().isLeaf()) {
exploreSelectedNode.setEnabled(false);
}
add(exploreSelectedNode);
addSeparator();
JTabbedPane tabs = cliGuiCtx.getTabs();
for (int i=0; i < tabs.getTabCount(); i++) {
GoToTabAction action = new GoToTabAction(i, tabs.getTitleAt(i));
JMenuItem item = new JMenuItem(action);
item.setToolTipText(tabs.getToolTipTextAt(i));
add(item);
}
}
public ButtonTabComponent(JTabbedPane pane, Function<CodeEditor<?, ?, ?>, Unit> callback) {
// unset default FlowLayout' gaps
super(new FlowLayout(FlowLayout.LEFT, 0, 0));
if (pane == null) {
throw new NullPointerException("TabbedPane is null");
}
this.pane = pane;
this.callback = callback;
setOpaque(false);
// make JLabel read titles from JTabbedPane
JLabel label = new JLabel() {
@Override
public String getText() {
int i = pane.indexOfTabComponent(ButtonTabComponent.this);
if (i != -1) {
return pane.getTitleAt(i);
}
return null;
}
};
add(label);
// add more space between the label and the button
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
// tab button
JButton button = new TabButton();
add(button);
// add more space to the top of the component
setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
}
public ButtonTabComponent(final JTabbedPane pane) {
//unset default FlowLayout' gaps
super(new FlowLayout(FlowLayout.LEFT, 0, 0));
if (pane == null) {
throw new NullPointerException("TabbedPane is null");
}
this.pane = pane;
setOpaque(false);
//make JLabel read titles from JTabbedPane
JLabel label = new JLabel() {
@Override
public String getText() {
int i = pane.indexOfTabComponent(ButtonTabComponent.this);
if (i != -1) {
return pane.getTitleAt(i);
}
return null;
}
};
add(label);
//add more space between the label and the button
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
//tab button
button = new TabButton();
add(button);
//add more space to the top of the component
setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
}
protected static String getItemText(JTabbedPane tabbedPane, int index) {
String titleAt = tabbedPane.getTitleAt(index);
if (titleAt == null || "".equals(titleAt)) {
return getTabNameFromIcon(tabbedPane, index);
}
return titleAt;
}
/**
* Creates a new button tab component.
*
* @param pane pane the button tab component belongs to.
*/
public ButtonTabComponent(final JTabbedPane pane) {
// unset default FlowLayout' gaps
super(new FlowLayout(FlowLayout.LEFT, 0, 0));
m_pane = Preconditions.checkNotNull(pane, "IE01213: TabbedPane is null");
setOpaque(false);
// make JLabel read titles from JTabbedPane
final JLabel label = new JLabel() {
private static final long serialVersionUID = 8139543899934835869L;
@Override
public String getText() {
final int index = pane.indexOfTabComponent(ButtonTabComponent.this);
if (index != -1) {
return pane.getTitleAt(index);
}
return null;
}
};
add(label);
// add more space between the label and the button
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
// tab button
final JButton button = new TabButton();
add(button);
// add more space to the top of the component
setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
}
private String getTitleIfKnownComponent(Component current) {
if (current instanceof JTabbedPane) {
final JTabbedPane tabbedPane = (JTabbedPane) current;
return tabbedPane.getTitleAt(tabbedPane.getSelectedIndex());
} else if (current instanceof JFrame) {
return ((JFrame) current).getTitle();
} else if (current instanceof JDialog) {
return ((JDialog) current).getTitle();
}
return null;
}
/**
* Constructor.
* @param pane JTabbedPane
*/
public MButtonTabComponent(final JTabbedPane pane) {
//unset default FlowLayout' gaps
super(new FlowLayout(FlowLayout.LEFT, 0, 0));
if (pane == null) {
throw new IllegalArgumentException("TabbedPane is null");
}
this.pane = pane;
setOpaque(false);
//make JLabel read titles from JTabbedPane
final JLabel label = new JLabel() {
private static final long serialVersionUID = 1L;
@Override
public String getText() {
final int i = pane.indexOfTabComponent(MButtonTabComponent.this);
if (i != -1) {
return pane.getTitleAt(i);
}
return null;
}
};
add(label);
//add more space between the label and the button
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
//tab button
final JButton button = new TabButton();
add(button);
//add more space to the top of the component
setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
}
public ButtonTabComponent(final JTabbedPane pane, ArrayList<AreaDeTexto> adts, ArrayList<String> arqsAbertos) {
//unset default FlowLayout' gaps
super(new FlowLayout(FlowLayout.LEFT, 0, 0));
if (pane == null) {
throw new NullPointerException("");
}
this.pane = pane;
this.adts = adts;
this.arquivosAbertos = arqsAbertos;
setOpaque(false);
//make JLabel read titles from JTabbedPane
JLabel label = new JLabel() {
public String getText() {
int i = pane.indexOfTabComponent(ButtonTabComponent.this);
if (i != -1) {
return pane.getTitleAt(i);
}
return null;
}
};
add(label);
//add more space between the label and the button
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
//tab button
JButton button = new TabButton();
add(button);
//add more space to the top of the component
setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
}
public ButtonTabComponent(final JTabbedPane pane) {
//unset default FlowLayout' gaps
super(new FlowLayout(FlowLayout.LEFT, 0, 0));
if (pane == null) {
throw new NullPointerException("TabbedPane is null");
}
this.pane = pane;
setOpaque(false);
//make JLabel read titles from JTabbedPane
JLabel label = new JLabel() {
public String getText() {
int i = pane.indexOfTabComponent(ButtonTabComponent.this);
if (i != -1) {
return pane.getTitleAt(i);
}
return null;
}
};
add(label);
//add more space between the label and the button
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
//tab button
JButton button = new TabButton();
add(button);
//add more space to the top of the component
setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
}