List of usage examples for javax.swing JTabbedPane getSelectedComponent
@Transient
public Component getSelectedComponent()
From source file:Main.java
public static void main(String[] args) { JTabbedPane tabbedPane = new JTabbedPane(); for (int i = 0; i < 5; i++) { tabbedPane.add("Tab " + i, new JLabel("Label " + i, SwingConstants.CENTER)); }/* w w w. ja v a 2s .c o m*/ tabbedPane.getModel().addChangeListener(e -> { JLabel label = (JLabel) tabbedPane.getSelectedComponent(); System.out.println(label.getText()); }); tabbedPane.setPreferredSize(new Dimension(500, 300)); JFrame frame = new JFrame(); frame.getContentPane().add(tabbedPane); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTabbedPane tabbedPane; JTextField txtFoo = new JTextField(10); JPanel pnlFoo = new JPanel(); pnlFoo.add(new JButton("Button 1")); pnlFoo.add(new JLabel("Foo")); pnlFoo.add(txtFoo);/*from w ww . j a va 2 s.c om*/ JTextField txtBar = new JTextField(10); JPanel pnlBar = new JPanel(); pnlBar.add(new JButton("Button 3")); pnlBar.add(new JLabel("Bar")); pnlBar.add(txtBar); tabbedPane = new JTabbedPane(); tabbedPane.addTab("Tab 1", pnlFoo); tabbedPane.addTab("Tab 2", pnlBar); tabbedPane.addChangeListener(e -> { Component comp = tabbedPane.getSelectedComponent(); if (comp.equals(pnlFoo)) { txtFoo.requestFocusInWindow(); } else if (comp.equals(pnlBar)) { txtBar.requestFocusInWindow(); } }); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(460, 200); frame.getContentPane().add(tabbedPane, BorderLayout.CENTER); frame.setVisible(true); txtFoo.requestFocusInWindow(); }
From source file:compecon.dashboard.panel.StatesPanel.java
public StatesPanel() { this.setLayout(new BorderLayout()); for (Currency currency : Currency.values()) { JPanel panelForCurrency = new StatePanelForCurrency(currency); jTabbedPaneCurrency.addTab(currency.getIso4217Code(), panelForCurrency); }/*w w w .ja v a 2 s . c o m*/ jTabbedPaneCurrency.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (e.getSource() instanceof JTabbedPane) { JTabbedPane pane = (JTabbedPane) e.getSource(); StatePanelForCurrency selectedComponent = (StatePanelForCurrency) pane.getSelectedComponent(); selectedComponent.notifyListener(); } } }); add(jTabbedPaneCurrency, BorderLayout.CENTER); }
From source file:compecon.dashboard.panel.BanksPanel.java
public BanksPanel() { this.setLayout(new BorderLayout()); for (Currency currency : Currency.values()) { JPanel panelForCurrency = new BanksPanelForCurrency(currency); jTabbedPaneCurrency.addTab(currency.getIso4217Code(), panelForCurrency); }/*from w ww .j a v a2 s.c om*/ jTabbedPaneCurrency.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (e.getSource() instanceof JTabbedPane) { JTabbedPane pane = (JTabbedPane) e.getSource(); BanksPanelForCurrency selectedComponent = (BanksPanelForCurrency) pane.getSelectedComponent(); selectedComponent.notifyListener(); } } }); add(jTabbedPaneCurrency, BorderLayout.CENTER); }
From source file:compecon.dashboard.panel.IndustriesPanel.java
public IndustriesPanel() { this.setLayout(new BorderLayout()); for (Currency currency : Currency.values()) { IndustriesPanelForCurrency panelForCurrency = new IndustriesPanelForCurrency(currency); jTabbedPaneCurrency.addTab(currency.getIso4217Code(), panelForCurrency); }/* w ww. j a v a 2s. c o m*/ jTabbedPaneCurrency.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (e.getSource() instanceof JTabbedPane) { JTabbedPane pane = (JTabbedPane) e.getSource(); IndustriesPanelForCurrency selectedComponent = (IndustriesPanelForCurrency) pane .getSelectedComponent(); selectedComponent.notifyListener(); } } }); add(jTabbedPaneCurrency, BorderLayout.CENTER); }
From source file:com.mc.printer.model.panel.task.BuildModelTask.java
@Override public Object doBackgrounp() { javax.swing.JTabbedPane tabs = AutoPrinterApp.getMainView().getMainWorkPanel(); if (tabs != null) { if (tabs.getSelectedIndex() >= 0) { Component selectedcom = tabs.getSelectedComponent(); if (selectedcom instanceof CanvasWork) { CanvasWork selectPanel = (CanvasWork) selectedcom; FormBeans beansForm = selectPanel.getBeansForm(); /**/ if (beansForm.getHeightcm() == 0 || beansForm.getWidthcm() == 0) { int res = BaseMessage.CONFIRM( "?\r\nA4."); if (res != JOptionPane.OK_OPTION) { return null; }//w w w . jav a2 s .co m } String imagePath = beansForm.getImgpath(); HashMap<String, ComponentBean> parameterMap = selectPanel.getSavedForms(); if (parameterMap.size() > 0) { Set set = parameterMap.keySet(); boolean foundKey = false; //??? List<ComponentBean> beans = new ArrayList(); Iterator it = set.iterator(); while (it.hasNext()) { ComponentBean com = parameterMap.get(it.next().toString()); beans.add(com); if (com.isIskey()) { foundKey = true; } } beansForm.setElements(beans); // // if (!foundKey) { // BaseMessage.ERROR("PRIMARY KEY."); // return null; // } BaseFileChoose fileChoose = new BaseFileChoose("?", new String[] { Constants.MODEL_SUFFIX }, AutoPrinterApp.getMainFrame()); String selectedPath = fileChoose.showSaveDialog(); if (!selectedPath.trim().equals("")) { //get formname selectedPath = selectedPath + File.separator + beansForm.getFormname(); //String time=DateHelper.format(new Date(), "yyyyMMddHHmmss"); String finalZip = selectedPath; if (!selectedPath.endsWith("." + Constants.MODEL_SUFFIX)) { finalZip = selectedPath + "." + Constants.MODEL_SUFFIX; } String tempDir = selectedPath + File.separator + Constants.MODEL_TEMP_DIR; File imageFile = new File(imagePath); String xmlPath = tempDir + File.separator + imageFile.getName() + ".xml"; XMLHelper helper = new XMLHelper(xmlPath, beansForm); try { helper.write(); } catch (JAXBException ex) { ex.printStackTrace(); logger.error(ex.getMessage()); return ex; } File paramFile = new File(xmlPath); if (paramFile.isFile() && paramFile.exists()) { try { FileUtils.copyFileToDirectory(imageFile, new File(tempDir)); ZipHelper.createZip(tempDir, finalZip); return "??.\r\n" + finalZip; } catch (IOException ex) { ex.printStackTrace(); logger.error(ex.getMessage()); return ex; } finally { try { FileUtils.deleteDirectory(new File(selectedPath)); } catch (IOException ex) { ex.printStackTrace(); logger.error(ex.getMessage()); return ex; } } } } } else { return "??."; } } else { return "??????."; } } else { return "."; } } else { return "."; } return null; }
From source file:compecon.dashboard.panel.HouseholdsPanel.java
public HouseholdsPanel() { this.setLayout(new BorderLayout()); for (Currency currency : Currency.values()) { HouseholdsPanelForCurrency panelForCurrency = new HouseholdsPanelForCurrency(currency); jTabbedPaneCurrency.addTab(currency.getIso4217Code(), panelForCurrency); panelForCurrency.setBackground(Color.lightGray); }/*from w ww .j a v a 2s .c o m*/ jTabbedPaneCurrency.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (e.getSource() instanceof JTabbedPane) { JTabbedPane pane = (JTabbedPane) e.getSource(); HouseholdsPanelForCurrency selectedComponent = (HouseholdsPanelForCurrency) pane .getSelectedComponent(); selectedComponent.notifyListener(); } } }); add(jTabbedPaneCurrency, BorderLayout.CENTER); }
From source file:com.mc.printer.model.panel.task.BuildGuideTask.java
@Override public Object doBackgrounp() { javax.swing.JTabbedPane tabs = AutoPrinterApp.getMainView().getMainWorkPanel(); if (tabs != null) { if (tabs.getSelectedIndex() >= 0) { Component selectedcom = tabs.getSelectedComponent(); if (selectedcom instanceof GuideWork) { GuideWork selectPanel = (GuideWork) selectedcom; GuideBean presentBeansForm = selectPanel.getBeansForm(); logger.debug("selected tab:" + selectPanel.getName()); //? GuideBean beansForm;// w w w. ja v a 2 s . c o m try { beansForm = presentBeansForm.clone(); } catch (CloneNotSupportedException ex) { logger.error(ex.getMessage()); beansForm = presentBeansForm; } String backGroundImg = beansForm.getBackgoundImg(); // Set<String> imgArray = new HashSet(); if (backGroundImg != null) { File file = new File(backGroundImg); if (file.exists() && file.isFile()) { beansForm.setBackgoundImg(file.getName()); imgArray.add(backGroundImg); } else { beansForm.setBackgoundImg(""); } } else { beansForm.setBackgoundImg(""); } HashMap<String, GuideCompBean> parameterMap = new HashMap<String, GuideCompBean>(); HashMap<String, GuideCompBean> parentParameterMap = selectPanel.getSavedForms(); deepCloneMap(parameterMap, parentParameterMap); if (parameterMap.size() > 0) { Set set = parameterMap.keySet(); //??? List<GuideCompBean> beans = new ArrayList(); Iterator it = set.iterator(); while (it.hasNext()) { GuideCompBean com = parameterMap.get(it.next().toString()); beans.add(com); String pressedIcon = com.getPressedIcon(); String icon = com.getIcon(); if (pressedIcon != null && !pressedIcon.equals("")) { File pressfile = new File(pressedIcon); if (pressfile.exists() && pressfile.isFile()) { imgArray.add(pressedIcon); com.setPressedIcon(pressfile.getName()); } else { com.setPressedIcon(""); } } if (icon != null && !icon.equals("")) { File iconfile = new File(icon); if (iconfile.exists() && iconfile.isFile()) { imgArray.add(icon); com.setIcon(iconfile.getName()); } else { com.setIcon(""); } } } beansForm.setElements(beans); BaseFileChoose fileChoose = new BaseFileChoose("?", new String[] { Constants.MODEL_SUFFIX }, AutoPrinterApp.getMainFrame()); String selectedPath = fileChoose.showSaveDialog(); if (!selectedPath.trim().equals("")) { //get formname selectedPath = selectedPath + File.separator + beansForm.getGuideName(); //String time=DateHelper.format(new Date(), "yyyyMMddHHmmss"); String finalZip = selectedPath; if (!selectedPath.endsWith("." + Constants.GUIDE_SUFFIX)) { finalZip = selectedPath + "." + Constants.GUIDE_SUFFIX; } String tempDir = selectedPath + File.separator + Constants.GUIDE_TEMP_DIR; String xmlPath = tempDir + File.separator + beansForm.getGuideName() + ".xml"; XMLHelper helper = new XMLHelper(xmlPath, beansForm); try { helper.write(); } catch (JAXBException ex) { ex.printStackTrace(); logger.error(ex.getMessage()); return ex; } File paramFile = new File(xmlPath); if (paramFile.isFile() && paramFile.exists()) { try { logger.info("copy file and zip temp for:" + tempDir + ",total of attached file:" + imgArray.size()); File _temp = new File(tempDir); for (String img : imgArray) { File imgFile = new File(img); logger.debug("copy image:" + imgFile.getName()); FileUtils.copyFileToDirectory(imgFile, _temp); } ZipHelper.createZip(tempDir, finalZip); logger.info("zip file successfully."); return "??.\r\n" + finalZip; } catch (IOException ex) { ex.printStackTrace(); logger.error(ex.getMessage()); return ex; } finally { try { FileUtils.deleteDirectory(new File(selectedPath)); } catch (IOException ex) { ex.printStackTrace(); logger.error(ex.getMessage()); return ex; } } } else { logger.error("generator faild for:" + xmlPath); } } } else { return "??."; } } else { return "??????."; } } else { return "?."; } } else { return "?."; } return null; }
From source file:org.nuclos.client.layout.wysiwyg.component.properties.PropertyChartPropertyDomainStep.java
@Override public void prepare() { super.prepare(); chart = model.getChart();/*from w w w . ja va 2 s .c om*/ wysiwygChart = model.getWYSIWYGChart(); String sPrefix = getChartProperty(Chart.PROPERTY_COMBINED_PREFIXES); combinedPrefixes = (sPrefix == null) ? new StringBuffer("") : new StringBuffer(sPrefix); panel = new JPanel(); panel.setLayout(new BorderLayout()); final ChartFunction chartFunction = getChartFunction(); if (!chartFunction.isCombinedChart()) { panel.add(getPanelComponent(chartFunction, ""), BorderLayout.CENTER); } else { JPanel editorType = new JPanel(); editorType.setLayout(new GridBagLayout()); JLabel propTypeValue = new JLabel( //SpringLocaleDelegate.getInstance().getMessage("wysiwyg.chart.wizard.domain.value", "Diagramm hinzufgen:"/*)*/); editorType.add(propTypeValue, new GridBagConstraints(0, 0, 0, 1, 1D, 1D, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0)); final JComboBox propTypeComponent = new JComboBox(chartFunction.getCombinedChartFunctions()); editorType.add(propTypeComponent, new GridBagConstraints(0, 1, 1, 1, 1D, 1D, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 15, 0), 0, 0)); final JTabbedPane tabbedPane = new JTabbedPane(); JButton removeButton = new JButton(iconRemove); removeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (tabbedPane.getSelectedIndex() != -1) { PanelComponent panelComponent = (PanelComponent) tabbedPane.getSelectedComponent(); combinedPrefixes = new StringBuffer( combinedPrefixes.toString().replaceAll(panelComponent.prefix, "")); tabbedPane.remove(panelComponent); } } }); editorType.add(removeButton, new GridBagConstraints(1, 1, 1, 1, 1D, 1D, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(5, 0, 0, 0), 0, 0)); JButton addButton = new JButton(iconAdd); addButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ChartFunction cFunction = (ChartFunction) propTypeComponent.getSelectedItem(); String prefix = cFunction.name() + "." + (Math.random() + "").replaceAll("\\.", "") + ":"; combinedPrefixes.append(prefix); tabbedPane.add(cFunction.name(), getPanelComponent(cFunction, prefix)); tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1); } }); editorType.add(addButton, new GridBagConstraints(2, 1, 1, 1, 1D, 1D, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 0, 0, 0), 0, 0)); String[] prefixes = combinedPrefixes.toString().split(":"); for (String prefix : prefixes) { if (prefix.length() > 0) { try { ChartFunction cFunction = ChartFunction.valueOf(prefix.split("\\.")[0]); tabbedPane.add(cFunction.name(), getPanelComponent(cFunction, prefix + ":")); } catch (Exception e) { // ignore. } } } panel.add(editorType, BorderLayout.NORTH); panel.add(tabbedPane, BorderLayout.CENTER); } }
From source file:burp.BurpExtender.java
@Override public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks) { // keep a reference to our callbacks object this.callbacks = callbacks; callbacks.registerContextMenuFactory(new ContextMenuFactory(this, callbacks)); // set our extension name callbacks.setExtensionName("Code Dx"); for (int i = 0; i < refreshSpinner.length; i++) refreshSpinner[i] = new ImageIcon(BurpExtender.class.getResource("/" + i + ".png")); // create our UI SwingUtilities.invokeLater(new Runnable() { @Override/* w w w.j av a 2 s .c o m*/ public void run() { pane = new JScrollPane(createMainPanel()); refreshAnimation = new ButtonAnimationThread(projectRefresh, refreshSpinner); callbacks.customizeUiComponent(pane); // add the custom tab to Burp's UI callbacks.addSuiteTab(BurpExtender.this); // add listener to update projects list when Code Dx tab selected Component parent = pane.getParent(); if (parent instanceof JTabbedPane) { final JTabbedPane tabs = (JTabbedPane) parent; final ChangeListener tabChangeListener = new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { if (pane == tabs.getSelectedComponent() && !updating && !"".equals(serverUrl.getText()) && !"".equals(apiKey.getText())) { Thread updateThread = new Thread() { public void run() { updateTargets(); updateProjects(true); } }; updateThread.start(); } else if (pane != tabs.getSelectedComponent()) { NameValuePair project = getProject(); if (project != null) callbacks.saveExtensionSetting(BurpExtender.PROJECT_KEY, project.getValue()); } } }; tabs.addChangeListener(tabChangeListener); //Remove the change listener when the extension is unloaded callbacks.registerExtensionStateListener(new IExtensionStateListener() { @Override public void extensionUnloaded() { tabs.removeChangeListener(tabChangeListener); } }); } } }); }