本文整理汇总了Java中javax.swing.JTabbedPane.indexOfTabComponent方法的典型用法代码示例。如果您正苦于以下问题:Java JTabbedPane.indexOfTabComponent方法的具体用法?Java JTabbedPane.indexOfTabComponent怎么用?Java JTabbedPane.indexOfTabComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTabbedPane
的用法示例。
在下文中一共展示了JTabbedPane.indexOfTabComponent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TabComponent
import javax.swing.JTabbedPane; //导入方法依赖的package包/类
/**
* Constructor for TabComponent class.
*
* @param pane
* {@link JTabbedPane} parent component.
* @param observer
* Main JNotepadPP frame.
* @param lp
* Localization provider.
*/
public TabComponent(JTabbedPane pane, JNotepadPP observer,
ILocalizationProvider lp) {
super(new FlowLayout(FlowLayout.LEFT, 0, 0));
this.lp = lp;
this.observer = observer;
setOpaque(false);
JLabel label = new JLabel() {
private static final long serialVersionUID = 1L;
public String getText() {
int i = pane.indexOfTabComponent(TabComponent.this);
if (i != -1) {
this.revalidate();
return pane.getTitleAt(i);
}
return "";
}
};
ImageIcon image = new ImageIcon(this.getClass().getResource(
"res/green.png"));
picLabel = new JLabel(image);
add(picLabel);
add(label);
picLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
closeButton = new CloseTabButton(this);
add(closeButton);
setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
}
示例2: actionPerformed
import javax.swing.JTabbedPane; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void actionPerformed(ActionEvent e) {
JTabbedPane pane = observer.getTabs();
int i = pane.indexOfTabComponent(tab);
JNotepadPPDocument editor = observer.getEditors().get(i);
List<JNotepadPPDocument> editors = observer.getEditors();
if (pane.getComponentCount() == 4) {
return;
}
if (editor.isChanged()) {
int answer = JOptionPane.showConfirmDialog(observer,
lp.getString("saveMessage"), lp.getString("saveDialog"),
JOptionPane.YES_NO_CANCEL_OPTION);
if (answer == JOptionPane.YES_OPTION) {
editor.saveDocument(false);
} else if (answer == JOptionPane.CANCEL_OPTION) {
return;
}
}
pane.remove(i);
editors.remove(i);
int size = editors.size();
if (i >= size) {
observer.setActiveEditor(editors.get(size - 1));
pane.setSelectedIndex(size - 1);
} else {
observer.setActiveEditor(editors.get(i));
pane.setSelectedIndex(i);
}
observer.getActiveEditor().updateStatusBar();
}
示例3: ButtonTabComponent
import javax.swing.JTabbedPane; //导入方法依赖的package包/类
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));
}