List of usage examples for javax.swing JTabbedPane getTabCount
@BeanProperty(bound = false) public int getTabCount()
tabbedpane
. From source file:Main.java
public static void main(String[] args) { JTabbedPane tab = new JTabbedPane(); tab.addTab("A", new JPanel()); tab.addTab("+", new JPanel()); tab.getModel().addChangeListener(new ChangeListener() { private int lastSelected; private boolean ignore = false; @Override/*from w w w. j a va 2 s . c o m*/ public void stateChanged(ChangeEvent e) { if (!ignore) { ignore = true; try { int selected = tab.getSelectedIndex(); String title = tab.getTitleAt(selected); if ("+".equals(title)) { JPanel pane = new JPanel(); tab.insertTab("Tab" + (tab.getTabCount() - 1), null, pane, null, lastSelected + 1); tab.setSelectedComponent(pane); } else { lastSelected = selected; } } finally { ignore = false; } } } }); final JButton btn = new JButton("Add"); btn.addActionListener(e -> System.out.println(tab.getTabCount())); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(tab); frame.add(btn, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:TabSample.java
static void add(JTabbedPane tabbedPane, String label) { int count = tabbedPane.getTabCount(); JButton button = new JButton(label); button.setBackground(colors[count]); tabbedPane.addTab(label, new ImageIcon("yourFile.gif"), button, label); }
From source file:TabSample.java
static void add(JTabbedPane tabbedPane, String label, int mnemonic) { int count = tabbedPane.getTabCount(); JButton button = new JButton(label); tabbedPane.addTab(label, new ImageIcon("yourFile.gif"), button, label); tabbedPane.setMnemonicAt(count, mnemonic); }
From source file:MainClass.java
static void add(JTabbedPane tabbedPane, String label, int mnemonic) { int count = tabbedPane.getTabCount(); JButton button = new JButton(label); tabbedPane.addTab(label, button);/*from w ww. j av a 2 s .c o m*/ tabbedPane.setMnemonicAt(count, mnemonic); }
From source file:TabbedPaneSample.java
static void add(JTabbedPane tabbedPane, String label) { int count = tabbedPane.getTabCount(); JButton button = new JButton(label); button.setBackground(colors[count]); tabbedPane.addTab(label, new DiamondIcon(colors[count]), button, label); }
From source file:Main.java
public static void setLocaleRecursively(final Component comp, final Locale l) { comp.setLocale(l);/*www. j av a 2 s . c o m*/ Component[] children = null; if (comp instanceof JMenu) { children = ((JMenu) comp).getMenuComponents(); } else if (comp instanceof JTabbedPane) { JTabbedPane tabbedPane = (JTabbedPane) comp; children = new Component[tabbedPane.getTabCount()]; for (int i = 0; i < children.length; i++) { children[i] = tabbedPane.getComponentAt(i); } } else if (comp instanceof Container) { children = ((Container) comp).getComponents(); } for (Component child : children) { setLocaleRecursively(child, l); } }
From source file:Main.java
public static void setFont(JComponent component, Font font, ComponentOrientation componentOrientation) { component.setFont(font);// w ww .jav a 2 s. co m if (component instanceof JTextField) { component.setComponentOrientation(componentOrientation); } if (component instanceof JTextArea) { component.setComponentOrientation(componentOrientation); } if (component instanceof JTextPane) { component.setComponentOrientation(componentOrientation); } if (component instanceof JScrollPane) { for (Component cmp : component.getComponents()) { setFont((JComponent) cmp, font, componentOrientation); } } if (component instanceof JTree) { component.setComponentOrientation(componentOrientation); } if (component instanceof JComboBox) { component.setComponentOrientation(componentOrientation); JComboBox comboBox = (JComboBox) component; ((BasicComboBoxRenderer) comboBox.getRenderer()).setHorizontalAlignment(SwingConstants.RIGHT); ((BasicComboBoxRenderer) comboBox.getRenderer()).setAutoscrolls(true); comboBox.setMaximumRowCount(20); } /* if(component instanceof JLabel) { ((JLabel)component).setHorizontalTextPosition(SwingConstants.RIGHT); }*/ if (component instanceof JPanel) { JPanel panel = (JPanel) component; if (panel.getBorder() != null && panel.getBorder() instanceof TitledBorder) { ((TitledBorder) panel.getBorder()).setTitleFont(font); panel.setComponentOrientation(componentOrientation); } for (Component cmp : component.getComponents()) { setFont((JComponent) cmp, font, componentOrientation); } } if (component instanceof JTabbedPane) { JTabbedPane tabbedPane = (JTabbedPane) component; int tabCount = tabbedPane.getTabCount(); for (int i = 0; i < tabCount; i++) { setFont((JComponent) tabbedPane.getComponentAt(i), font, componentOrientation); } } }
From source file:tourma.utils.web.WebStatistics.java
/** * /*from w w w . java 2 s .c om*/ */ public static String getHTML() { StringBuffer stats = new StringBuffer(""); JPNStatistics jpn = new JPNStatistics(); jpn.setSize(640, 480); JTabbedPane jtp = jpn.getTabbedPane(); for (int i = 0; i < jtp.getTabCount(); i++) { Component comp = jtp.getComponent(i); if (comp instanceof ChartPanel) { ChartPanel panel = (ChartPanel) comp; panel.setSize(640, 480); BufferedImage buf = new BufferedImage(640, 480, BufferedImage.TYPE_INT_ARGB); Graphics g = buf.createGraphics(); panel.print(g); g.dispose(); //BufferedImage buf = toBufferedImage(img, 640, 480); String img_str = WebPicture.getPictureAsHTML(buf, 640, 480, true); stats.append(img_str); } if (comp instanceof JPanel) { // Find JList, Select All then Find ChartPanel JPanel pane = (JPanel) comp; ChartPanel panel = null; JList list = null; for (int j = 0; j < pane.getComponentCount(); j++) { Component c = pane.getComponent(j); if (c instanceof JScrollPane) { for (int k = 0; k < ((JScrollPane) c).getViewport().getComponentCount(); k++) { Component c2 = ((JScrollPane) c).getViewport().getComponent(k); if (c2 instanceof JList) { list = (JList) c2; } } } } if (list != null) { int start = 0; int end = list.getModel().getSize() - 1; if (end >= 0) { list.setSelectionInterval(start, end); } jpn.updatePositions(); } for (int j = 0; j < pane.getComponentCount(); j++) { Component c = pane.getComponent(j); if (c instanceof ChartPanel) { panel = (ChartPanel) c; } } if (panel != null) { panel.setSize(640, 480); BufferedImage buf = new BufferedImage(640, 480, BufferedImage.TYPE_INT_ARGB); Graphics g = buf.createGraphics(); panel.print(g); g.dispose(); //BufferedImage buf = toBufferedImage(img, 640, 480); String img_str = WebPicture.getPictureAsHTML(buf, 640, 480, true); stats.append(img_str); } } } return stats.toString(); }
From source file:TabSample.java
static void addIt(JTabbedPane tabbedPane, String text) { JLabel label = new JLabel(text); JButton button = new JButton(text); JPanel panel = new JPanel(); panel.add(label);// w w w . j a v a 2 s .co m panel.add(button); tabbedPane.addTab(text, panel); tabbedPane.setTabComponentAt(tabbedPane.getTabCount() - 1, new JTextField(text)); }
From source file:Main.java
@Override public void paint(Graphics g, JComponent c) { super.paint(g, c); if (c instanceof JLayer == false) { return;//from ww w. ja va 2s .co m } JLayer jlayer = (JLayer) c; JTabbedPane tabPane = (JTabbedPane) jlayer.getView(); for (int i = 0; i < tabPane.getTabCount(); i++) { Rectangle rect = tabPane.getBoundsAt(i); Dimension d = button.getPreferredSize(); int x = rect.x + rect.width - d.width - 2; int y = rect.y + (rect.height - d.height) / 2; Rectangle r = new Rectangle(x, y, d.width, d.height); button.setForeground(r.contains(pt) ? Color.RED : Color.BLACK); SwingUtilities.paintComponent(g, button, p, r); } }