下面列出了javax.swing.JTabbedPane#getSelectedIndex ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private MouseAdapter onAddNewTDTab() {
return new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent me) {
JTabbedPane tabbedPane = (JTabbedPane) me.getSource();
if (tabbedPane.getSelectedIndex() != -1 && getSelectedData() == null) {
Rectangle rect = tabbedPane.getUI().
getTabBounds(tabbedPane, tabbedPane.getSelectedIndex());
if (rect.contains(me.getPoint())) {
tabbedPane.setSelectedIndex(tabbedPane.getSelectedIndex() - 1);
addNewTestData(tabbedPane);
}
}
}
};
}
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 + "'");
}
}
}
}
private void TabInspectorStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_TabInspectorStateChanged
JTabbedPane sourceTabbedPane = (JTabbedPane) evt.getSource();
int index = sourceTabbedPane.getSelectedIndex();
if (index == 1) {
DoComandoExterno(Controler.menuComandos.cmdTreeNavegador);
Manager.setTextoDica(null, "");
} else {
if (Manager != null) {
if (index == 0) {
inspector1.PerformDica();
} else {
inspector2.PerformDica();
}
}
}
}
/**
* create a GUI to give the user transport layer options.
* @param parent the root gui component
* @return a new connection or null.
*/
static public NetworkConnection requestNewConnection(Component parent) {
JTabbedPane tabs = new JTabbedPane();
tabs.addTab(Translator.get("Local"), serial.getTransportLayerPanel());
tabs.addTab(Translator.get("Remote"), tcp.getTransportLayerPanel());
tabs.setSelectedIndex(selectedLayer);
JPanel top = new JPanel(new BorderLayout());
top.add(tabs,BorderLayout.CENTER);
int result = JOptionPane.showConfirmDialog(parent, top, Translator.get("MenuConnect"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
Component c = tabs.getSelectedComponent();
selectedLayer = tabs.getSelectedIndex();
if(c instanceof TransportLayerPanel) {
return ((TransportLayerPanel)c).openConnection();
}
}
// cancelled connect
return null;
}
public static String getSelectedItemText(JTabbedPane component) {
int selectedIndex = component.getSelectedIndex();
if (selectedIndex != -1) {
return JTabbedPaneTabJavaElement.getText(component, selectedIndex);
}
return "";
}
@Override
public void stateChanged(ChangeEvent e) {
JTabbedPane tp = (JTabbedPane) component;
int selectedIndex = tp.getSelectedIndex();
if (selectedIndex != -1) {
recorder.recordSelect(this, JTabbedPaneTabJavaElement.getText(tp, selectedIndex));
}
}
/**
* Listens to events from the tab pane, displays different
* categories of data accordingly.
*/
public void stateChanged(ChangeEvent e) {
setName(NbBundle.getBundle(TransactionView.class).getString("MON_Title"));
JTabbedPane p = (JTabbedPane)e.getSource();
displayType = p.getSelectedIndex();
showData();
}
@Override
public void stateChanged (ChangeEvent e) {
Object source = e.getSource();
if (source instanceof JTabbedPane) {
JTabbedPane tabPane = (JTabbedPane) source;
if (handledViews.containsKey(tabPane)) {
diffViewMode = tabPane.getSelectedIndex();
}
}
}
private void closeTestData(Object source) {
JTabbedPane tab = (JTabbedPane) source;
TestDataTablePanel panel = getSelectedData();
if (!panel.isGlobalData) {
int index = tab.getSelectedIndex();
tab.setSelectedIndex(index - 1);
tab.removeTabAt(index);
}
}
@Override
public void stateChanged(ChangeEvent e) {
JTabbedPane tabPane = (JTabbedPane) e.getSource();
tabPane.revalidate();
tabPane.repaint();
if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) {
int index = tabPane.getSelectedIndex();
if (index < rects.length && index != -1) {
tabScroller.tabPanel.scrollRectToVisible(rects[index]);
}
}
}
public void stateChanged(ChangeEvent e)
{
JTabbedPane pane = (JTabbedPane)e.getSource();
int index = pane.getSelectedIndex();
if (index != -1)
{
fireExecuterTabActivated(_executors.get(index));
}
}
@Override
public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, int x, int y, int w, int h,
int tabIndex, int orientation) {
JTabbedPane t = (JTabbedPane) context.getComponent();
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (t.getSelectedIndex() == tabIndex) {
g.setColor(BG);
}
else {
g.setColor(INACTIVE);
}
g.fillRoundRect(x, y, w - 2, h, 5, 5);
g.fillRect(x, y + 5, w - 2, h - 3);
}
@Override
public void paintTabbedPaneTabBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex) {
JTabbedPane t = (JTabbedPane) context.getComponent();
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (t.getSelectedIndex() == tabIndex) {
g.setColor(ACCENT);
g.fillRoundRect(x, y, w - 2, 5, 5, 5);
g.setColor(BG);
g.fillRect(x, y + 2, w - 2, 4);
}
}
public void actionPerformed(ActionEvent ae) {
JTabbedPane tabs = cliGuiCtx.getTabs();
int newTabIndex = tabs.getSelectedIndex() + 1;
ManagementModelNode newRoot = node.clone();
tabs.insertTab(calcTabName(this.node), null, new ManagementModel(newRoot, cliGuiCtx), newRoot.addressPath(), newTabIndex);
tabs.setTabComponentAt(newTabIndex, new ButtonTabComponent(tabs));
tabs.setSelectedIndex(newTabIndex);
}
private void calcDBSearch() {
JTabbedPane tabPane = dbsearch.getTabPane();
System.out.println("run DB search " + tabPane.getSelectedIndex());
Structure s = null;
boolean domainSplit = dbsearch.isDomainSplit();
StructurePairSelector tab = null;
int pos = tabPane.getSelectedIndex();
if (pos == 0 ){
tab = dbsearch.getSelectPDBPanel();
} else if (pos == 1){
tab = dbsearch.getScopSelectPanel();
} else if (pos == 2){
tab = dbsearch.getPDBUploadPanel();
}
try {
s = tab.getStructure1();
if ( s == null) {
JOptionPane.showMessageDialog(null,"please select structure 1");
return ;
}
} catch (Exception e){
e.printStackTrace();
}
String name1 = s.getName();
if ( name1 == null || name1.equals(""))
name1 = s.getPDBCode();
System.out.println("name1 in alig gui:" + name1);
String file = dbsearch.getOutFileLocation();
if ( file == null || file.equals("") ){
JOptionPane.showMessageDialog(null,"Please select a directory to contain the DB search results.");
return;
}
File outFile = new File(file);
if( !outFile.exists() ) {
outFile.mkdirs();
}
if( !outFile.isDirectory() || !outFile.canWrite()) {
JOptionPane.showMessageDialog(null,"Unable to write to "+outFile.getAbsolutePath());
return;
}
UserConfiguration config = WebStartMain.getWebStartConfig();
int totalNrCPUs = Runtime.getRuntime().availableProcessors();
int useNrCPUs = 1;
if ( totalNrCPUs > 1){
Object[] options = new Integer[totalNrCPUs];
int posX = 0;
for ( int i = totalNrCPUs; i> 0 ; i--){
options[posX] = i;
posX++;
}
int n = JOptionPane.showOptionDialog(null,
"How many would you like to use for the calculations?",
"We detected " + totalNrCPUs + " processors on your system.",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]);
if ( n < 0)
return;
useNrCPUs = (Integer) options[n];
System.out.println("will use " + useNrCPUs + " CPUs." );
}
System.out.println("using domainSplit data");
alicalc = new AlignmentCalcDB(this, s, name1,config,file, domainSplit);
alicalc.setNrCPUs(useNrCPUs);
abortB.setEnabled(true);
progress.setIndeterminate(true);
ProgressThreadDrawer drawer = new ProgressThreadDrawer(progress);
drawer.start();
Thread t = new Thread(alicalc);
t.start();
}