javax.swing.JTabbedPane.getSelectedIndex()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(275)

本文整理了Java中javax.swing.JTabbedPane.getSelectedIndex()方法的一些代码示例,展示了JTabbedPane.getSelectedIndex()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTabbedPane.getSelectedIndex()方法的具体详情如下:
包路径:javax.swing.JTabbedPane
类名称:JTabbedPane
方法名:getSelectedIndex

JTabbedPane.getSelectedIndex介绍

暂无

代码示例

代码示例来源:origin: deathmarine/Luyten

private boolean isTabInForeground(OpenFile open) {
  String title = open.name;
  int selectedIndex = house.getSelectedIndex();
  return (selectedIndex >= 0 && selectedIndex == house.indexOfTab(title));
}

代码示例来源:origin: deathmarine/Luyten

@Override
public void actionPerformed(ActionEvent e) {
  closeOpenTab(house.getSelectedIndex());
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
  JFrame frame = new JFrame();
  frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  frame.setBounds(0, 0, 300, 400);
  frame.setLayout(null);
  final JTabbedPane tabbedPane = new JTabbedPane();
  tabbedPane.addTab("One", new JPanel());
  tabbedPane.addTab("Two", new JPanel());
  tabbedPane.addTab("Three", new JPanel());
  tabbedPane.addChangeListener(new ChangeListener() {
    public void stateChanged(ChangeEvent e) {
      System.out.println("Tab: " + tabbedPane.getSelectedIndex());
    }
  });
  tabbedPane.setBounds(0, 0, 300, 400);
  frame.add(tabbedPane);
  frame.setVisible(true);
}

代码示例来源:origin: deathmarine/Luyten

@Override
  public void mouseClicked(MouseEvent e) {
    if (SwingUtilities.isMiddleMouseButton(e)) {
      closeOpenTab(house.getSelectedIndex());
    }
  }
});

代码示例来源:origin: igniterealtime/Smack

@Override
  public void actionPerformed(ActionEvent e) {
    // Remove the selected tab pane if it's not the Smack info pane
    if (tabbedPane.getSelectedIndex() < tabbedPane.getComponentCount() - 1) {
      int index = tabbedPane.getSelectedIndex();
      // Notify to the debugger to stop debugging
      EnhancedDebugger debugger = debuggers.get(index);
      debugger.cancel();
      // Remove the debugger from the root window
      tabbedPane.remove(debugger.tabbedPane);
      debuggers.remove(debugger);
      // Update the root window title
      frame.setTitle(
          "Smack Debug Window -- Total connections: "
              + (tabbedPane.getComponentCount() - 1));
    }
  }
});

代码示例来源:origin: deathmarine/Luyten

public String getCurrentTabTitle() {
  String tabTitle = null;
  try {
    int pos = house.getSelectedIndex();
    if (pos >= 0) {
      tabTitle = house.getTitleAt(pos);
    }
  } catch (Exception e1) {
    Luyten.showExceptionDialog("Exception!", e1);
  }
  if (tabTitle == null) {
    getLabel().setText("No open tab");
  }
  return tabTitle;
}

代码示例来源:origin: deathmarine/Luyten

@Override
  public void stateChanged(ChangeEvent e) {
    int selectedIndex = house.getSelectedIndex();
    if (selectedIndex < 0) {
      return;
    }
    for (OpenFile open : hmap) {
      if (house.indexOfTab(open.name) == selectedIndex) {
        if (open.getType() != null && !open.isContentValid()) {
          updateOpenClass(open);
          break;
        }
      }
    }
  }
}

代码示例来源:origin: deathmarine/Luyten

public RSyntaxTextArea getCurrentTextArea() {
  RSyntaxTextArea currentTextArea = null;
  try {
    int pos = house.getSelectedIndex();
    System.out.println(pos);
    if (pos >= 0) {
      RTextScrollPane co = (RTextScrollPane) house.getComponentAt(pos);
      currentTextArea = (RSyntaxTextArea) co.getViewport().getView();
    }
  } catch (Exception e1) {
    Luyten.showExceptionDialog("Exception!", e1);
  }
  if (currentTextArea == null) {
    getLabel().setText("No open tab");
  }
  return currentTextArea;
}

代码示例来源:origin: deathmarine/Luyten

@Override
  public void actionPerformed(ActionEvent e) {
    JTabbedPane house = mainWindow.getModel().house;
    
    if (e.getModifiers() != 2 || house.getTabCount() == 0)
      mainWindow.onCloseFileMenu();
    else {
      mainWindow.getModel().closeOpenTab(house.getSelectedIndex());
    }
  }
});

代码示例来源:origin: ron190/jsql-injection

@Override
  public void actionPerformed(ActionEvent e) {
    if (valuesTabbedPane.getTabCount() > 0) {
      int selectedIndex = valuesTabbedPane.getSelectedIndex();
      if (selectedIndex + 1 < valuesTabbedPane.getTabCount()) {
        valuesTabbedPane.setSelectedIndex(selectedIndex + 1);
      } else {
        valuesTabbedPane.setSelectedIndex(0);
      }
    }
  }
};

代码示例来源:origin: ron190/jsql-injection

@Override
  public void actionPerformed(ActionEvent e) {
    if (valuesTabbedPane.getTabCount() > 0) {
      int selectedIndex = valuesTabbedPane.getSelectedIndex();
      if (selectedIndex - 1 > -1) {
        valuesTabbedPane.setSelectedIndex(selectedIndex - 1);
      } else {
        valuesTabbedPane.setSelectedIndex(valuesTabbedPane.getTabCount() - 1);
      }
    }
  }
};

代码示例来源:origin: ron190/jsql-injection

@Override
public void mouseWheelMoved(MouseWheelEvent e) {
  JTabbedPane tabPane = (JTabbedPane) e.getSource();
  int dir = -e.getWheelRotation();
  int selIndex = tabPane.getSelectedIndex();
  int maxIndex = tabPane.getTabCount() - 1;
  if ((selIndex == 0 && dir < 0) || (selIndex == maxIndex && dir > 0)) {
    selIndex = maxIndex - selIndex;
  } else {
    selIndex += dir;
  }
  if (0 <= selIndex && selIndex < tabPane.getTabCount()) {
    // Fix #54575: NullPointerException on setSelectedIndex()
    try {
      tabPane.setSelectedIndex(selIndex);
    } catch (NullPointerException err) {
      LOGGER.error(err, err);
    }
  }
}

代码示例来源:origin: ron190/jsql-injection

protected DnDTabbedPane() {
  super();
  Handler h = new Handler();
  this.addMouseListener(h);
  this.addMouseMotionListener(h);
  this.addPropertyChangeListener(h);
  
  this.addMouseWheelListener(mouseWheelEvent -> {
    JTabbedPane tabPane = (JTabbedPane) mouseWheelEvent.getSource();
    
    int dir = -mouseWheelEvent.getWheelRotation();
    int selIndex = tabPane.getSelectedIndex();
    int maxIndex = tabPane.getTabCount() - 1;
    
    if ((selIndex == 0 && dir < 0) || (selIndex == maxIndex && dir > 0)) {
      selIndex = maxIndex - selIndex;
    } else {
      selIndex += dir;
    }
    
    if (0 <= selIndex && selIndex < tabPane.getTabCount()) {
      tabPane.setSelectedIndex(selIndex);
    }
  });
  
  // UIManager.put() is not enough
  this.setUI(new CustomMetalTabbedPaneUI());
  this.setBorder(BorderFactory.createMatteBorder(0, 1, 0, 0, HelperUi.COLOR_COMPONENT_BORDER));
}

代码示例来源:origin: ron190/jsql-injection

if (tabs.getSelectedIndex() > -1) {
  Component currentTabHeader = tabs.getTabComponentAt(tabs.getSelectedIndex());
  if (currentTabHeader != null) {
    currentTabHeader.setFont(currentTabHeader.getFont().deriveFont(Font.PLAIN));

代码示例来源:origin: Audiveris/audiveris

@Override
public void actionPerformed (ActionEvent e)
{
  int tabIndex = stubsPane.getSelectedIndex();
  if (tabIndex > 0) {
    stubsPane.setSelectedIndex(tabIndex - 1);
  }
}

代码示例来源:origin: chatty/chatty

public void setSelectedPrevious() {
  int index = tabs.getSelectedIndex();
  int count = tabs.getTabCount();
  if (count > 0) {
    if (index-1 >= 0) {
      tabs.setSelectedIndex(index-1);
    } else {
      tabs.setSelectedIndex(count -1);
    }
  }
}

代码示例来源:origin: locationtech/jts

private void updateStatsPanelIfVisible()
{
 int index = inputTabbedPane.getSelectedIndex();
 if (index < 0) return;
 if (inputTabbedPane.getComponent(index) == statsPanel) {
  statsPanel.refresh();         
 }   
}

代码示例来源:origin: nccgroup/AutoRepeater

@Override
public byte[] getRequest() {
 switch (tabs.getSelectedIndex()) {
  case 0:
   return currentOriginalRequestResponse.getRequest();
  case 1:
   return currentModifiedRequestResponse.getRequest();
  default:
   return new byte[0];
 }
}

代码示例来源:origin: hneemann/Digital

@Override
  public void actionPerformed(ActionEvent e) {
    int tab = tp.getSelectedIndex();
    if (tab < 0) tab = 0;
    JFileChooser fileChooser = new MyFileChooser();
    fileChooser.setFileFilter(new FileNameExtensionFilter("Comma Separated Values", "csv"));
    new SaveAsHelper(ValueTableDialog.this, fileChooser, "csv")
        .checkOverwrite(resultTableData.get(tab)::saveCSV);
  }
}.setToolTip(Lang.get("menu_saveData_tt")).createJMenuItem());

代码示例来源:origin: hneemann/Digital

@Override
  public void actionPerformed(ActionEvent actionEvent) {
    int tab = tp.getSelectedIndex();
    if (tab < 0) tab = 0;
    new GraphDialog(ValueTableDialog.this, Lang.get("win_testdata_N", tp.getTitleAt(tab)), resultTableData.get(tab))
        .disableTable()
        .setVisible(true);
  }
}.setToolTip(Lang.get("menu_showDataAsGraph_tt"));

相关文章

JTabbedPane类方法