List of usage examples for javax.swing JTabbedPane setPreferredSize
@BeanProperty(preferred = true, description = "The preferred size of the component.") public void setPreferredSize(Dimension preferredSize)
From source file:Main.java
public static void main(String[] args) { JPanel ui = new JPanel(new BorderLayout(1, 1)); JTabbedPane jtp = new JTabbedPane(JTabbedPane.LEFT); jtp.addTab("Apple", new JLabel("Apple")); jtp.addTab("Banana", new JLabel("Banana")); jtp.addTab("Cherries", new JLabel("Cherries")); jtp.addTab("Grapes", new JLabel("Grapes")); ui.add(jtp, BorderLayout.CENTER); jtp.setPreferredSize(new Dimension(200, 200)); jtp.addChangeListener(e -> {/*from w w w. j a va2s . c om*/ if (e.getSource() instanceof JTabbedPane) { JTabbedPane pane = (JTabbedPane) e.getSource(); System.out.println("Selected paneNo : " + pane.getSelectedIndex()); } }); }
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)); }//from w w w. ja v a2 s . 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:mekhq.gui.FinancesTab.java
@Override public void initTab() { resourceMap = ResourceBundle.getBundle("mekhq.resources.FinancesTab", new EncodeControl()); //$NON-NLS-1$ GridBagConstraints gridBagConstraints; setLayout(new GridBagLayout()); ChartPanel financeAmountPanel = (ChartPanel) createGraphPanel(GraphType.BALANCE_AMOUNT); ChartPanel financeMonthlyPanel = (ChartPanel) createGraphPanel(GraphType.MONTHLY_FINANCES); financeModel = new FinanceTableModel(); financeTable = new JTable(financeModel); financeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); financeTable.addMouseListener(new FinanceTableMouseAdapter(getCampaignGui(), financeTable, financeModel)); financeTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); TableColumn column = null;/*from w w w.j av a 2 s . c om*/ for (int i = 0; i < FinanceTableModel.N_COL; i++) { column = financeTable.getColumnModel().getColumn(i); column.setPreferredWidth(financeModel.getColumnWidth(i)); column.setCellRenderer(financeModel.getRenderer()); } financeTable.setIntercellSpacing(new Dimension(0, 0)); financeTable.setShowGrid(false); loanModel = new LoanTableModel(); loanTable = new JTable(loanModel); loanTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); loanTable.addMouseListener(new LoanTableMouseAdapter(getCampaignGui(), loanTable, loanModel)); loanTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); column = null; for (int i = 0; i < LoanTableModel.N_COL; i++) { column = loanTable.getColumnModel().getColumn(i); column.setPreferredWidth(loanModel.getColumnWidth(i)); column.setCellRenderer(loanModel.getRenderer()); } loanTable.setIntercellSpacing(new Dimension(0, 0)); loanTable.setShowGrid(false); JScrollPane scrollLoanTable = new JScrollPane(loanTable); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; JPanel panBalance = new JPanel(new GridBagLayout()); panBalance.add(new JScrollPane(financeTable), gridBagConstraints); panBalance.setMinimumSize(new java.awt.Dimension(350, 100)); panBalance.setBorder(BorderFactory.createTitledBorder("Balance Sheet")); JPanel panLoan = new JPanel(new GridBagLayout()); panLoan.add(scrollLoanTable, gridBagConstraints); JTabbedPane financeTab = new JTabbedPane(); financeTab.setMinimumSize(new java.awt.Dimension(450, 300)); financeTab.setPreferredSize(new java.awt.Dimension(450, 300)); JSplitPane splitFinances = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panBalance, financeTab); splitFinances.setOneTouchExpandable(true); splitFinances.setContinuousLayout(true); splitFinances.setResizeWeight(1.0); splitFinances.setName("splitFinances"); financeTab.addTab(resourceMap.getString("activeLoans.text"), panLoan); financeTab.addTab(resourceMap.getString("cbillsBalanceTime.text"), financeAmountPanel); financeTab.addTab(resourceMap.getString("monthlyRevenueExpenditures.text"), financeMonthlyPanel); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; add(splitFinances, gridBagConstraints); JPanel panelFinanceRight = new JPanel(new BorderLayout()); JPanel pnlFinanceBtns = new JPanel(new GridLayout(2, 2)); btnAddFunds = new JButton("Add Funds (GM)"); btnAddFunds.addActionListener(ev -> addFundsActionPerformed()); btnAddFunds.setEnabled(getCampaign().isGM()); pnlFinanceBtns.add(btnAddFunds); JButton btnGetLoan = new JButton("Get Loan"); btnGetLoan.addActionListener(e -> showNewLoanDialog()); pnlFinanceBtns.add(btnGetLoan); btnManageAssets = new JButton("Manage Assets (GM)"); btnManageAssets.addActionListener(e -> manageAssets()); btnManageAssets.setEnabled(getCampaign().isGM()); pnlFinanceBtns.add(btnManageAssets); panelFinanceRight.add(pnlFinanceBtns, BorderLayout.NORTH); areaNetWorth = new JTextArea(); areaNetWorth.setLineWrap(true); areaNetWorth.setWrapStyleWord(true); areaNetWorth.setFont(new Font("Courier New", Font.PLAIN, 12)); areaNetWorth.setText(getCampaign().getFinancialReport()); areaNetWorth.setEditable(false); JScrollPane descriptionScroll = new JScrollPane(areaNetWorth); panelFinanceRight.add(descriptionScroll, BorderLayout.CENTER); areaNetWorth.setCaretPosition(0); descriptionScroll.setMinimumSize(new Dimension(300, 200)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.gridheight = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 0.0; gridBagConstraints.weighty = 1.0; add(panelFinanceRight, gridBagConstraints); }
From source file:org.webcat.plugintester.ui.MainFrameBuilder.java
/** * Creates and lays out the Swing components for the window. * * @param frame the JFrame instance that will contain the components */// ww w . ja v a 2 s. c om private void constructFrame(JFrame frame) { GridBagConstraints gridBagConstraints; fileChooser = new JFileChooser(); bottomPanel = new JPanel(); runButton = new JButton(); mainPanel = new JPanel(); JLabel webCatHomeLabel = new JLabel(); webCatHomeField = new JTextField(); webCatHomeBrowseButton = new JButton(); JSeparator jSeparator0 = new JSeparator(); JLabel submissionLabel = new JLabel(); submissionField = new JTextField(); submissionBrowseButton = new JButton(); JSeparator jSeparator1 = new JSeparator(); JLabel pluginsLabel = new JLabel(); JPanel pluginsPanel = new JPanel(); JScrollPane pluginsScrollPane = new JScrollPane(); pluginsTable = new JTable(); pluginAddButton = new JButton(); pluginRemoveButton = new JButton(); JSeparator jSeparator2 = new JSeparator(); JTabbedPane tabPane = new JTabbedPane(); propertiesPanel = new JPanel(); JScrollPane propertiesScrollPane = new JScrollPane(); propertiesEditor = new JEditorPane(); documentationPanel = new JPanel(); JScrollPane documentationScrollPane = new JScrollPane(); documentationEditor = new JEditorPane(); // File chooser fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); // Bottom panel bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 4)); // Run button runButton.setText("Run Plug-ins"); runButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { runButtonActionPerformed(evt); } }); bottomPanel.add(runButton); frame.getContentPane().add(bottomPanel, BorderLayout.PAGE_END); // Main panel mainPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); mainPanel.setLayout(new GridBagLayout()); // Web-CAT Home field gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = GridBagConstraints.RELATIVE; gridBagConstraints.anchor = GridBagConstraints.LINE_START; webCatHomeLabel.setText("Web-CAT Home:"); mainPanel.add(webCatHomeLabel, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; webCatHomeField.setTransferHandler(new WebCATHomeTransferHandler()); mainPanel.add(webCatHomeField, gridBagConstraints); // Web-CAT Home browse button webCatHomeBrowseButton.setText("Browse..."); webCatHomeBrowseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { webCatHomeBrowseButtonActionPerformed(evt); } }); mainPanel.add(webCatHomeBrowseButton, new GridBagConstraints()); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(jSeparator0, gridBagConstraints); // Submission field gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = GridBagConstraints.RELATIVE; gridBagConstraints.anchor = GridBagConstraints.LINE_START; submissionLabel.setText("Submission:"); mainPanel.add(submissionLabel, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; submissionField.setTransferHandler(new SubmissionTransferHandler()); mainPanel.add(submissionField, gridBagConstraints); // Submission browse button submissionBrowseButton.setText("Browse..."); submissionBrowseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { submissionBrowseButtonActionPerformed(evt); } }); mainPanel.add(submissionBrowseButton, new GridBagConstraints()); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(jSeparator1, gridBagConstraints); // Plug-ins area pluginsLabel.setText("Plug-ins to run:"); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(pluginsLabel, gridBagConstraints); pluginsPanel.setPreferredSize(new Dimension(400, 80)); pluginsPanel.setLayout(new GridBagLayout()); pluginsModel = new PluginsTableModel(); pluginsTable.setModel(pluginsModel); pluginsTable.setColumnSelectionAllowed(true); pluginsTable.getTableHeader().setReorderingAllowed(false); pluginsScrollPane.setViewportView(pluginsTable); pluginsTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); pluginsTable.getColumnModel().getColumn(0).setResizable(false); pluginsScrollPane.setTransferHandler(new PluginsTransferHandler()); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridheight = GridBagConstraints.REMAINDER; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; pluginsPanel.add(pluginsScrollPane, gridBagConstraints); pluginAddButton.setText("Add..."); pluginAddButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pluginAddButtonActionPerformed(evt); } }); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.PAGE_START; pluginsPanel.add(pluginAddButton, gridBagConstraints); pluginRemoveButton.setText("Remove"); pluginRemoveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pluginRemoveButtonActionPerformed(evt); } }); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.PAGE_START; pluginsPanel.add(pluginRemoveButton, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 0.25; mainPanel.add(pluginsPanel, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(jSeparator2, gridBagConstraints); tabPane.setPreferredSize(new Dimension(466, 150)); propertiesPanel.setLayout(new GridBagLayout()); propertiesEditor.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { propertiesTimer.restart(); } }); propertiesTimer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent e) { updateGradingProperties(); } }); propertiesScrollPane.setViewportView(propertiesEditor); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; propertiesPanel.add(propertiesScrollPane, gridBagConstraints); tabPane.addTab("Properties", propertiesPanel); documentationPanel.setLayout(new GridBagLayout()); documentationEditor.setContentType("text/html"); documentationEditor.setEditable(false); documentationScrollPane.setViewportView(documentationEditor); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; documentationPanel.add(documentationScrollPane, gridBagConstraints); tabPane.addTab("Documentation", documentationPanel); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; gridBagConstraints.gridheight = GridBagConstraints.REMAINDER; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weighty = 1.0; mainPanel.add(tabPane, gridBagConstraints); frame.getContentPane().add(mainPanel, BorderLayout.CENTER); frame.pack(); }
From source file:pcgen.gui2.dialog.AboutDialog.java
/** * This method is called from within the constructor to * initialize the form.//w w w.j a v a 2 s. com */ private void initComponents() { JTabbedPane mainPane = new JTabbedPane(); mainPane.add(LanguageBundle.getString("in_abt_credits"), buildCreditsPanel()); //$NON-NLS-1$ mainPane.add(LanguageBundle.getString("in_abt_libraries"), buildIncludesPanel()); //$NON-NLS-1$ mainPane.add(LanguageBundle.getString("in_abt_license"), buildLicensePanel()); //$NON-NLS-1$ mainPane.add(LanguageBundle.getString("in_abt_awards"), buildAwardsPanel()); //$NON-NLS-1$ setLayout(new BorderLayout()); add(mainPane, BorderLayout.CENTER); mainPane.setPreferredSize(new Dimension(640, 480)); }