Java Code Examples for javax.swing.JPanel#getPreferredSize()
The following examples show how to use
javax.swing.JPanel#getPreferredSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnalyzeDialog.java From FancyBing with GNU General Public License v3.0 | 6 votes |
public AnalyzeDialog(Frame owner, Listener listener, ArrayList<AnalyzeDefinition> commands, GuiGtpClient gtp, MessageDialogs messageDialogs) { super(owner, i18n("TIT_ANALYZE")); m_messageDialogs = messageDialogs; m_gtp = gtp; m_commands = commands; m_listener = listener; Container contentPane = getContentPane(); JPanel commandPanel = createCommandPanel(); contentPane.add(commandPanel, BorderLayout.CENTER); comboBoxChanged(); setSelectedColor(BLACK); int minWidth = commandPanel.getPreferredSize().width; setMinimumSize(new Dimension(minWidth, 192)); pack(); addWindowListener(new WindowAdapter() { public void windowActivated(WindowEvent e) { m_comboBoxHistory.requestFocusInWindow(); } }); }
Example 2
Source File: ReferencesBrowserController.java From netbeans with Apache License 2.0 | 6 votes |
Dialog createProgressPanel(final String message, BoundedRangeModel model) { Dialog dialog; JPanel panel = new JPanel(); panel.setLayout(new BorderLayout(10, 10)); panel.setBorder(new EmptyBorder(15, 15, 15, 15)); panel.add(new JLabel(message), BorderLayout.NORTH); final Dimension ps = panel.getPreferredSize(); ps.setSize(Math.max(ps.getWidth(), DEFAULT_WIDTH), Math.max(ps.getHeight(), DEFAULT_HEIGHT)); panel.setPreferredSize(ps); final JProgressBar progress = new JProgressBar(); if (model == null) { progress.setIndeterminate(true); } else { progress.setStringPainted(true); progress.setModel(model); } panel.add(progress, BorderLayout.SOUTH); dialog = DialogDisplayer.getDefault().createDialog(new DialogDescriptor(panel, Bundle.ReferencesBrowserController_ProgressDialogCaption(), true, new Object[] { }, DialogDescriptor.CANCEL_OPTION, DialogDescriptor.RIGHT_ALIGN, null, null)); return dialog; }
Example 3
Source File: InfoPanel.java From freecol with GNU General Public License v2.0 | 6 votes |
/** * Fill map transform information into a new panel and add it. * * @param mapTransform The {@code MapTransform} to display. * @return The {@code MapTransform}. */ private MapTransform fillMapPanel(MapTransform mapTransform) { MigPanel panel = new MigPanel(new BorderLayout()); final JPanel p = (mapTransform == null) ? null : mapTransform.getDescriptionPanel(); if (p != null) { p.setOpaque(false); final Dimension d = p.getPreferredSize(); p.setBounds(0, (this.getHeight() - d.height)/2, this.getWidth(), d.height); panel.add(p, BorderLayout.CENTER); } setPanel(panel); return mapTransform; }
Example 4
Source File: ReferencesBrowserController.java From visualvm with GNU General Public License v2.0 | 6 votes |
Dialog createProgressPanel(final String message, BoundedRangeModel model) { Dialog dialog; JPanel panel = new JPanel(); panel.setLayout(new BorderLayout(10, 10)); panel.setBorder(new EmptyBorder(15, 15, 15, 15)); panel.add(new JLabel(message), BorderLayout.NORTH); final Dimension ps = panel.getPreferredSize(); ps.setSize(Math.max(ps.getWidth(), DEFAULT_WIDTH), Math.max(ps.getHeight(), DEFAULT_HEIGHT)); panel.setPreferredSize(ps); final JProgressBar progress = new JProgressBar(); if (model == null) { progress.setIndeterminate(true); } else { progress.setStringPainted(true); progress.setModel(model); } panel.add(progress, BorderLayout.SOUTH); dialog = DialogDisplayer.getDefault().createDialog(new DialogDescriptor(panel, Bundle.ReferencesBrowserController_ProgressDialogCaption(), true, new Object[] { }, DialogDescriptor.CANCEL_OPTION, DialogDescriptor.RIGHT_ALIGN, null, null)); return dialog; }
Example 5
Source File: SettingsPanel.java From netbeans with Apache License 2.0 | 5 votes |
private static int defaultHeight() { if (DEFAULT_HEIGHT == -1) { JPanel ref = new JPanel(null); ref.setLayout(new BoxLayout(ref, BoxLayout.LINE_AXIS)); ref.setOpaque(false); ref.add(new JLabel("XXX")); // NOI18N ref.add(new JButton("XXX")); // NOI18N ref.add(new PopupButton("XXX")); // NOI18N ref.add(new JCheckBox("XXX")); // NOI18N ref.add(new JRadioButton("XXX")); // NOI18N ref.add(new JTextField("XXX")); // NOI18N ref.add(new JExtendedSpinner(new SpinnerNumberModel(1, 1, 655535, 1))); Component separator = Box.createHorizontalStrut(1); Dimension d = separator.getMaximumSize(); d.height = 20; separator.setMaximumSize(d); ref.add(separator); DEFAULT_HEIGHT = ref.getPreferredSize().height; } return DEFAULT_HEIGHT; }
Example 6
Source File: SettingsPanel.java From visualvm with GNU General Public License v2.0 | 5 votes |
private static int defaultHeight() { if (DEFAULT_HEIGHT == -1) { JPanel ref = new JPanel(null); ref.setLayout(new BoxLayout(ref, BoxLayout.LINE_AXIS)); ref.setOpaque(false); ref.add(new JLabel("XXX")); // NOI18N ref.add(new JButton("XXX")); // NOI18N ref.add(new PopupButton("XXX")); // NOI18N ref.add(new JCheckBox("XXX")); // NOI18N ref.add(new JRadioButton("XXX")); // NOI18N ref.add(new JTextField("XXX")); // NOI18N ref.add(new JExtendedSpinner(new SpinnerNumberModel(1, 1, 655535, 1))); Component separator = Box.createHorizontalStrut(1); Dimension d = separator.getMaximumSize(); d.height = 20; separator.setMaximumSize(d); ref.add(separator); DEFAULT_HEIGHT = ref.getPreferredSize().height; } return DEFAULT_HEIGHT; }
Example 7
Source File: PumpernickelShowcaseApp.java From pumpernickel with MIT License | 5 votes |
/** * Create the application icon. * * This should be called on the EDT, because it creates/renders JComponents. */ private static BufferedImage createAppImage() { BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); JPanel p = new JPanel(); p.setOpaque(false); QPanelUI qui = new QPanelUI(); qui.setCalloutSize(10); qui.setCornerSize(10); qui.setCalloutType(CalloutType.BOTTOM_CENTER); qui.setFillColor1(Color.white); qui.setFillColor2(new Color(0xececec)); qui.setShadowSize(5); qui.setStrokeColor(new Color(0x787878)); p.setUI(qui); JSwitchButton switchButton1 = new JSwitchButton(true); JSwitchButton switchButton2 = new JSwitchButton(false); p.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; c.insets = new Insets(4, 4, 4, 4); p.add(switchButton1, c); c.gridy++; p.add(switchButton2, c); Dimension d = p.getPreferredSize(); d.width = Math.max(d.width, d.height); d.height = Math.max(d.width, d.height); p.setSize(d); p.getLayout().layoutContainer(p); p.paint(g); g.dispose(); return bi; }
Example 8
Source File: SplashFrame.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
public SplashFrame() { super(new Frame()); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage(MainFrame.class.getResource("SplashBug1.png")); Image image2 = toolkit.getImage(MainFrame.class.getResource("SplashBug2B.png")); Image imageReverse = toolkit.getImage(MainFrame.class.getResource("SplashBug1reverse.png")); Image image2Reverse = toolkit.getImage(MainFrame.class.getResource("SplashBug2reverseB.png")); JLabel l = new JLabel(new ImageIcon(MainFrame.class.getResource("spotbugs.png"))); JPanel p = new JPanel(); Viewer viewer = new Viewer(image, image2, imageReverse, image2Reverse); final JPanel bottom = viewer; p.setBackground(Color.white); bottom.setBackground(Color.white); p.add(l); getContentPane().add(p, BorderLayout.CENTER); getContentPane().add(bottom, BorderLayout.SOUTH); pack(); Dimension labelSize = l.getPreferredSize(); p.setPreferredSize(new Dimension(labelSize.width + 50, labelSize.height + 20)); p.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); bottom.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); Dimension panelSize = p.getPreferredSize(); bottom.setPreferredSize(new Dimension(panelSize.width, image.getHeight(null) + 2)); setLocationRelativeTo(null); // g.drawImage(new ImageIcon("bugSplash3.png"),0 ,0 ,null); pack(); viewer.animate(); }
Example 9
Source File: OutOfDateDialog.java From triplea with GNU General Public License v3.0 | 5 votes |
static Component showOutOfDateComponent(final Version latestVersionOut) { final JPanel panel = new JPanel(new BorderLayout()); final JEditorPane intro = new JEditorPane("text/html", getOutOfDateMessage(latestVersionOut)); intro.setEditable(false); intro.setOpaque(false); intro.setBorder(BorderFactory.createEmptyBorder()); final HyperlinkListener hyperlinkListener = e -> { if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) { OpenFileUtility.openUrl(e.getDescription()); } }; intro.addHyperlinkListener(hyperlinkListener); panel.add(intro, BorderLayout.NORTH); final JEditorPane updates = new JEditorPane("text/html", getOutOfDateReleaseUpdates()); updates.setEditable(false); updates.setOpaque(false); updates.setBorder(BorderFactory.createEmptyBorder()); updates.addHyperlinkListener(hyperlinkListener); updates.setCaretPosition(0); final JScrollPane scroll = new JScrollPane(updates); panel.add(scroll, BorderLayout.CENTER); final Dimension maxDimension = panel.getPreferredSize(); maxDimension.width = Math.min(maxDimension.width, 700); maxDimension.height = Math.min(maxDimension.height, 480); panel.setMaximumSize(maxDimension); panel.setPreferredSize(maxDimension); return panel; }
Example 10
Source File: TransferViewBuilder.java From raccoon4 with Apache License 2.0 | 5 votes |
protected void add(TransferWorker tw) { TransferPeerBuilder peer = tw.getPeer(); JPanel ctrl = peer.withBorder(BorderFactory.createEtchedBorder()) .build(globals); Dimension d = ctrl.getPreferredSize(); d.width = ITEMWIDTH; ctrl.setPreferredSize(d); // last item is always the spacer. list.add(ctrl, contentConstraints, list.getComponentCount() - 1); peers.add(peer); list.revalidate(); }
Example 11
Source File: MessagePanel.java From magarena with GNU General Public License v3.0 | 5 votes |
private void setMessagePanelLayout(final JComponent container, SwingGameController aController) { final int GAP = 8; // pixels setLayout(new MigLayout("insets 0, gap " + GAP, "[][][grow,right]", "[top]")); JPanel playerPanel = getPlayerPanel(); JPanel turnPanel = getTurnPanel(); final Insets insets1 = container.getInsets(); final Insets insets2 = SEPARATOR_BORDER.getBorderInsets(this); final int totalInsets = insets1.left + insets1.right + insets2.left + insets2.right; if (textLabelWidth == 0) { textLabelWidth = container.getWidth() - playerPanel.getPreferredSize().width - turnPanel.getPreferredSize().width - totalInsets - (GAP * 2); } final TextLabel textLabel = new TextLabel( message.getText(), LogStackViewer.MESSAGE_FONT, textLabelWidth, false, LogStackViewer.CHOICE_COLOR, aController ); add(playerPanel); add(textLabel); add(turnPanel); }
Example 12
Source File: PopupList.java From netbeans with Apache License 2.0 | 4 votes |
static JPopupMenu createPopup() { NotificationDisplayerImpl displayer = NotificationDisplayerImpl.getInstance(); List<NotificationImpl> notifications = displayer.getNotifications(); if( notifications.isEmpty() ) return null; JPopupMenu res = new JPopupMenu(); Dimension prefSize = new Dimension(); int avgRowHeight = 0; int rowCount = 0; final JPanel panel = new JPanel( new GridBagLayout()); final JScrollPane scroll = new JScrollPane(panel); panel.setOpaque(true); Color panelBackground = UIManager.getColor("nb.core.ui.popupList.background"); //NOI18N if( null == panelBackground ) panelBackground = UIManager.getColor("Tree.background"); //NOI18N panel.setBackground( panelBackground ); for( NotificationImpl n : notifications ) { final JPanel row = new JPanel(new GridBagLayout()); row.setOpaque(false); JComponent component = n.getPopupComponent(); if( null == component ) { continue; //just in case... } row.add(component, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2,2,2,2), 1, 1)); JButton btnDismiss = new BalloonManager.DismissButton(); final NotificationImpl notification = n; btnDismiss.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { notification.clear(); panel.remove(row); panel.getParent().invalidate(); panel.getParent().repaint(); panel.getParent().getParent().invalidate(); panel.getParent().getParent().repaint(); if( panel.getComponentCount() == 1 ) PopupList.dismiss(); } }); row.add(btnDismiss, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(5,3,3,3), 1, 1)); panel.add(row, new GridBagConstraints(0, rowCount, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0,0,0,0), 1, 1)); Dimension size = row.getPreferredSize(); if( size.width > prefSize.width ) prefSize.width = size.width; if( rowCount++ < MAX_VISIBLE_ROWS ) prefSize.height += size.height; avgRowHeight += size.height; } panel.add(new JLabel(), new GridBagConstraints(0, rowCount, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0,0,0,0), 1, 1)); avgRowHeight /= notifications.size(); scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scroll.setBorder(BorderFactory.createEmptyBorder()); scroll.getVerticalScrollBar().setUnitIncrement(avgRowHeight); scroll.getVerticalScrollBar().setBlockIncrement(MAX_VISIBLE_ROWS*avgRowHeight); int scrollBarWidth = scroll.getVerticalScrollBar().getPreferredSize().width; if( scrollBarWidth <= 0 ) scrollBarWidth = UIManager.getInt("ScrollBar.width"); //NOI18N if( scrollBarWidth <= 0 ) scrollBarWidth = 18; //let's take some reasonable guess prefSize.width += scrollBarWidth; Insets i = scroll.getInsets(); if( null != i ) { prefSize.width += i.left + i.right; prefSize.height += i.top + i.bottom; } if( rowCount <= MAX_VISIBLE_ROWS ) prefSize = panel.getPreferredSize(); prefSize.height = Math.min( prefSize.height, 600 ); if( prefSize.width > 800 ) { prefSize.width = 800; scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); } scroll.getViewport().setPreferredSize(prefSize); scroll.getViewport().setMinimumSize(prefSize); res.add( scroll ); return res; }
Example 13
Source File: AbstractSearchDialog.java From pumpernickel with MIT License | 4 votes |
/** * Creates an <code>AbstractSearchDialog</code>. * * @param comp * only used to identify the frame to bind this dialog to. */ public AbstractSearchDialog(JComponent comp) { super(getFrame(comp), strings.getString("dialogTitle")); Color fg = UIManager.getColor("Label.disabledForeground"); if (fg != null) { notFound.setForeground(fg); } JPanel notFoundContainer = new JPanel(); notFoundContainer.add(notFound); Dimension preferredSize = notFoundContainer.getPreferredSize(); notFoundContainer.setPreferredSize(preferredSize); notFoundContainer.setMinimumSize(preferredSize); notFound.setVisible(false); nextButton.setToolTipText(strings.getString("nextTip")); prevButton.setToolTipText(strings.getString("previousTip")); DialogFooter footer = new DialogFooter( new JComponent[] { notFoundContainer }, new JComponent[] { nextButton, prevButton }, false, nextButton); setFooter(footer); JPanel content = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.EAST; c.insets = new Insets(3, 3, 3, 3); c.weightx = 0; c.weighty = 0; content.add(findLabel, c); c.anchor = GridBagConstraints.WEST; c.weightx = 1; c.fill = GridBagConstraints.HORIZONTAL; c.gridx++; content.add(textField, c); setContent(content); nextButton.addActionListener(actionListener); prevButton.addActionListener(actionListener); setModal(false); setCloseable(true); pack(); }
Example 14
Source File: CollapsibleContainer.java From pumpernickel with MIT License | 4 votes |
protected LayoutBlueprint(boolean initialPermitLocked) { super(ANIMATION_DURATION, 1F); this.initialPermitLocked = initialPermitLocked; Insets insets = getInsets(); int height = getHeight() - insets.top - insets.bottom; int remainingHeight = height; float totalVerticalWeight = 0; Map<JComponent, Number> verticalWeightMap = new HashMap<JComponent, Number>(); for (int a = 0; a < sections.size(); a++) { Section section = sections.get(a); JPanel body = section.getBody(); JButton header = getHeader(section); Boolean collapsed = (Boolean) header .getClientProperty(COLLAPSED); if (collapsed == null) collapsed = Boolean.FALSE; if (!header.isVisible()) collapsed = true; components.add(header); components.add(body); if (header.isVisible()) visibleComponents.add(header); if ((!collapsed)) visibleComponents.add(body); Number n = (Number) section.getProperty(VERTICAL_WEIGHT); if (n == null) n = 0; if (visibleComponents.contains(body)) { totalVerticalWeight += n.floatValue(); if (n.floatValue() != 0) verticalWeightMap.put(body, n); } if (visibleComponents.contains(header)) { Dimension headerSize = header.getPreferredSize(); heightMap.put(header, headerSize.height); remainingHeight -= headerSize.height; } else { heightMap.put(header, 0); } originalHeightMap.put(header, header.getHeight()); if (visibleComponents.contains(body) && n.floatValue() == 0) { Dimension bodySize = body.getPreferredSize(); heightMap.put(body, bodySize.height); remainingHeight -= bodySize.height; } else { heightMap.put(body, 0); } originalHeightMap.put(body, body.getHeight()); } if (remainingHeight > 0 && totalVerticalWeight > 0) { // divide the remaining height based on the vertical weight int designatedHeight = 0; JComponent lastC = null; for (JComponent jc : verticalWeightMap.keySet()) { Number weight = verticalWeightMap.get(jc); int i = (int) (weight.floatValue() / totalVerticalWeight * remainingHeight); heightMap.put(jc, heightMap.get(jc) + i); designatedHeight += i; lastC = jc; } // due to rounding error, we may have a few extra pixels: int remainingPixels = remainingHeight - designatedHeight; // tack them on to someone. anyone. heightMap.put(lastC, heightMap.get(lastC) + remainingPixels); } }
Example 15
Source File: TraceEventTypePopupMenu.java From pega-tracerviewer with Apache License 2.0 | 4 votes |
public JComponent getCheckBoxLabelMenuItemListJComponent() { JPanel checkBoxLabelMenuItemListJPanel = getCheckBoxLabelMenuItemListJPanel(); JScrollPane jscrollPane = new JScrollPane(checkBoxLabelMenuItemListJPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); int vbarWidth = jscrollPane.getVerticalScrollBar().getPreferredSize().width; int hbarHeight = jscrollPane.getHorizontalScrollBar().getPreferredSize().height + 3/* border size */; int compWidth = checkBoxLabelMenuItemListJPanel.getPreferredSize().width; int compHeight = checkBoxLabelMenuItemListJPanel.getPreferredSize().height; int newCompWidth = compWidth + vbarWidth; int newCompHeight = compHeight + hbarHeight; Dimension newDim = new Dimension(newCompWidth, newCompHeight); jscrollPane.setPreferredSize(newDim); jscrollPane.getVerticalScrollBar().setUnitIncrement(14); return jscrollPane; }