本文整理匯總了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));
}