List of usage examples for javax.swing JComponent setMaximumSize
@BeanProperty(description = "The maximum size of the component.") public void setMaximumSize(Dimension maximumSize)
From source file:BoxAlignmentDemo.java
protected JPanel createLabelAndComponent(boolean doItRight) { JPanel pane = new JPanel(); JComponent component = new JPanel(); Dimension size = new Dimension(150, 100); component.setMaximumSize(size); component.setPreferredSize(size);/* ww w. j av a2 s . c o m*/ component.setMinimumSize(size); TitledBorder border = new TitledBorder(new LineBorder(Color.black), "A JPanel", TitledBorder.CENTER, TitledBorder.BELOW_TOP); border.setTitleColor(Color.black); component.setBorder(border); JLabel label = new JLabel("This is a JLabel"); String title; if (doItRight) { title = "Matched"; label.setAlignmentX(CENTER_ALIGNMENT); } else { title = "Mismatched"; } pane.setBorder(BorderFactory.createTitledBorder(title)); pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); pane.add(label); pane.add(component); return pane; }
From source file:com.limegroup.gnutella.gui.GUIUtils.java
public static void restrictSize(JComponent component, SizePolicy sizePolicy, boolean addClientProperty) { switch (sizePolicy) { case RESTRICT_HEIGHT: int height = component.getPreferredSize().height; int width = component.getPreferredSize().width; component.setMinimumSize(new Dimension(width, height)); //component.setPreferredSize(new Dimension(width, height)); component.setMaximumSize(new Dimension(Integer.MAX_VALUE, height)); break;/*from w ww.j a va 2 s . com*/ case RESTRICT_BOTH: height = component.getPreferredSize().height; width = component.getPreferredSize().width; component.setMinimumSize(new Dimension(width, height)); //component.setPreferredSize(STANDARD_DIMENSION); component.setMaximumSize(new Dimension(width, height)); break; case RESTRICT_NONE: component.setMinimumSize(null); component.setMaximumSize(null); } if (addClientProperty) { component.putClientProperty(SizePolicy.class, sizePolicy); } }
From source file:BoxAlignmentDemo.java
protected JPanel createYAlignmentExample(boolean doItRight) { JPanel pane = new JPanel(); String title;/*from w w w .j av a 2s . c o m*/ JComponent component1 = new JPanel(); Dimension size = new Dimension(100, 50); component1.setMaximumSize(size); component1.setPreferredSize(size); component1.setMinimumSize(size); TitledBorder border = new TitledBorder(new LineBorder(Color.black), "A JPanel", TitledBorder.CENTER, TitledBorder.BELOW_TOP); border.setTitleColor(Color.black); component1.setBorder(border); JComponent component2 = new JPanel(); size = new Dimension(100, 50); component2.setMaximumSize(size); component2.setPreferredSize(size); component2.setMinimumSize(size); border = new TitledBorder(new LineBorder(Color.black), "A JPanel", TitledBorder.CENTER, TitledBorder.BELOW_TOP); border.setTitleColor(Color.black); component2.setBorder(border); if (doItRight) { title = "Matched"; } else { component1.setAlignmentY(TOP_ALIGNMENT); title = "Mismatched"; } pane.setBorder(BorderFactory.createTitledBorder(title)); pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS)); pane.add(component1); pane.add(component2); return pane; }
From source file:de.tud.kom.p2psim.impl.skynet.visualization.MetricsPlot.java
private void setSizeOfComponent(JComponent component, Dimension dim) { component.setMinimumSize(dim);/*from w w w . j a v a 2s.c om*/ component.setMaximumSize(dim); component.setPreferredSize(dim); component.setSize(dim); }
From source file:davmail.ui.SettingsFrame.java
protected void addSettingComponent(JPanel panel, String label, JComponent component, String toolTipText) { JLabel fieldLabel = new JLabel(label); fieldLabel.setHorizontalAlignment(SwingConstants.RIGHT); fieldLabel.setVerticalAlignment(SwingConstants.CENTER); panel.add(fieldLabel);/*from w w w .j a v a 2s .com*/ component.setMaximumSize(component.getPreferredSize()); JPanel innerPanel = new JPanel(); innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.X_AXIS)); innerPanel.add(component); panel.add(innerPanel); if (toolTipText != null) { fieldLabel.setToolTipText(toolTipText); component.setToolTipText(toolTipText); } }
From source file:davmail.ui.SettingsFrame.java
protected void addPortSettingComponent(JPanel panel, String label, JComponent component, JComponent checkboxComponent, JComponent checkboxSSLComponent, String toolTipText) { JLabel fieldLabel = new JLabel(label); fieldLabel.setHorizontalAlignment(SwingConstants.RIGHT); fieldLabel.setVerticalAlignment(SwingConstants.CENTER); panel.add(fieldLabel);//from w w w .jav a 2 s . c o m component.setMaximumSize(component.getPreferredSize()); JPanel innerPanel = new JPanel(); innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.X_AXIS)); innerPanel.add(checkboxComponent); innerPanel.add(component); innerPanel.add(checkboxSSLComponent); panel.add(innerPanel); if (toolTipText != null) { fieldLabel.setToolTipText(toolTipText); component.setToolTipText(toolTipText); } }
From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java
private void computePreferredSizes() { for (String key : sizeGroups.keySet()) { int width = -1; int height = -1; for (JComponent component : sizeGroups.get(key)) { if (width < component.getPreferredSize().width) { width = component.getPreferredSize().width; }//from w w w.java 2 s. c om if (height < component.getPreferredSize().height) { height = component.getPreferredSize().height; } } // Sometimes the preferred width of a component can be too small to accommodate the contained text and in // that case the text is truncated and ellipsis will be shown. To fix it the width is increased. width += 2; for (JComponent component : sizeGroups.get(key)) { component.setMinimumSize(new Dimension(width, height)); component.setMaximumSize(new Dimension(width, height)); component.setPreferredSize(new Dimension(width, height)); } } sizeGroups.clear(); }
From source file:com.diversityarrays.kdxplore.curate.SampleEntryPanel.java
private JPanel generateStatControls() { JPanel statsPanel = new JPanel(); GBH gbh = new GBH(statsPanel); int x = 0;//from w ww . j ava2s . com for (StatType statType : StatType.values()) { JButton button = new JButton(statType.label); button.addActionListener(statButtonActionListener); statButtonByStatType.put(statType, button); JComponent valueLabel = null; if (statType == StatType.MODE) { JComboBox<String> combo = new JComboBox<String>(); combo.addActionListener(statButtonActionListener); valueLabel = combo; valueLabel.setMaximumSize(new Dimension(100, 25)); } else { JButton btn = new JButton(); btn.addActionListener(statButtonActionListener); valueLabel = btn; } statComponentByStatType.put(statType, valueLabel); statTypeByButton.put(valueLabel, statType); Font myFont = new Font(Font.SANS_SERIF, Font.BOLD, 10); TitledBorder roundedTitledBorder = new TitledBorder(BorderFactory.createRaisedBevelBorder(), statType.name(), 1, 2, myFont); valueLabel.setBorder(roundedTitledBorder); gbh.add(x, 0, 1, 1, GBH.BOTH, 2, 3, GBH.CENTER, valueLabel); x++; } return statsPanel; }
From source file:greenfoot.gui.export.ExportPublishPane.java
/** * Creates the scenario information display including information such as title, description, url. * For an update (isUpdate = true), the displayed options are slightly different. *//* ww w .j a va 2 s . c o m*/ private void createScenarioDisplay() { leftPanel = new Box(BoxLayout.Y_AXIS); JLabel text; MiksGridLayout titleAndDescLayout = new MiksGridLayout(6, 2, 8, 8); titleAndDescLayout.setVerticallyExpandingRow(3); titleAndDescPanel = new JPanel(titleAndDescLayout); titleAndDescPanel.setBackground(background); if (imagePanel == null) { imagePanel = new ImageEditPanel(IMAGE_WIDTH, IMAGE_HEIGHT); imagePanel.setBackground(background); } Box textPanel = new Box(BoxLayout.Y_AXIS); { text = new JLabel(Config.getString("export.publish.image1")); text.setAlignmentX(Component.RIGHT_ALIGNMENT); text.setFont(font); textPanel.add(text); text = new JLabel(Config.getString("export.publish.image2")); text.setAlignmentX(Component.RIGHT_ALIGNMENT); text.setFont(font); textPanel.add(text); } titleAndDescPanel.add(textPanel); titleAndDescPanel.add(imagePanel); if (isUpdate) { text = new JLabel(Config.getString("export.snapshot.label"), SwingConstants.TRAILING); text.setFont(font); titleAndDescPanel.add(text); keepScenarioScreenshot = new JCheckBox(); keepScenarioScreenshot.setSelected(true); // "keep screenshot" defaults to true, therefore the image panel should be disabled imagePanel.enableImageEditPanel(false); keepScenarioScreenshot.setName(Config.getString("export.publish.keepScenario")); keepScenarioScreenshot.setOpaque(false); keepScenarioScreenshot.addChangeListener(this); titleAndDescPanel.add(keepScenarioScreenshot); } text = new JLabel(Config.getString("export.publish.title"), SwingConstants.TRAILING); text.setFont(font); titleAndDescPanel.add(text); String title = project.getName(); if (getTitle() != null) { title = getTitle(); } titleField = new JTextField(title); titleField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { String text = titleField.getText(); return text.length() > 0; } }); titleField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { checkForExistingScenario(); } }); titleAndDescPanel.add(titleField); // If there is an update a "changes" description area is shown. // If not there a short description and long description area are shown. if (isUpdate) { JLabel updateLabel = new JLabel(Config.getString("export.publish.update"), SwingConstants.TRAILING); updateLabel.setVerticalAlignment(SwingConstants.TOP); updateLabel.setFont(font); updateArea = new JTextArea(); updateArea.setRows(6); updateArea.setLineWrap(true); updateArea.setWrapStyleWord(true); JScrollPane updatePane = new JScrollPane(updateArea); titleAndDescPanel.add(updateLabel); titleAndDescPanel.add(updatePane); titleAndDescLayout.setVerticallyExpandingRow(4); } else { text = new JLabel(Config.getString("export.publish.shortDescription"), SwingConstants.TRAILING); text.setFont(font); shortDescriptionField = new JTextField(); titleAndDescPanel.add(text); titleAndDescPanel.add(shortDescriptionField); text = new JLabel(Config.getString("export.publish.longDescription"), SwingConstants.TRAILING); text.setVerticalAlignment(SwingConstants.TOP); text.setFont(font); descriptionArea = new JTextArea(); descriptionArea.setRows(6); descriptionArea.setLineWrap(true); descriptionArea.setWrapStyleWord(true); JScrollPane description = new JScrollPane(descriptionArea); titleAndDescPanel.add(text); titleAndDescPanel.add(description); } text = new JLabel(Config.getString("export.publish.url"), SwingConstants.TRAILING); text.setFont(font); titleAndDescPanel.add(text); urlField = new JTextField(); titleAndDescPanel.add(urlField); leftPanel.add(titleAndDescPanel, BorderLayout.SOUTH); JComponent sourceAndLockPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 8, 0)); { sourceAndLockPanel.setBackground(background); includeSource = new JCheckBox(Config.getString("export.publish.includeSource")); includeSource.setOpaque(false); includeSource.setSelected(false); includeSource.setFont(font); sourceAndLockPanel.add(includeSource); lockScenario.setFont(font); sourceAndLockPanel.add(lockScenario); sourceAndLockPanel.setMaximumSize(sourceAndLockPanel.getPreferredSize()); } leftPanel.add(sourceAndLockPanel, BorderLayout.SOUTH); }
From source file:openlr.mapviewer.coding.ui.AbstractCodingOptionsDialog.java
/** * Creates a new instance. Sets up the entire dialog. * /*from w w w . j a v a2 s . c om*/ * @param type * The type of coding this dialog instance is dealing with * @param propsHolder * The encoding and decoding properties holder * @param fcf * The file choose factory to use * @param title * The dialog title */ public AbstractCodingOptionsDialog(final CodingType type, final CodingPropertiesHolder propsHolder, final FileChooserFactory fcf, final String title) { codingType = type; setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setTitle(title); setResizable(false); JPanel contentPane = new JPanel(new MigLayout("insets 0", "[grow]", "[][bottom]")); setContentPane(contentPane); JButton applyBtn = new JButton("Apply"); applyBtn.setToolTipText("Stores the current settings for the current MapViewer run"); ApplyChangesListener applyListener = new ApplyChangesListener(type, propsHolder, optionsTextFields); applyBtn.addActionListener(applyListener); defaultConfig = loadDefaultSettings(); JButton resetBtn = new JButton("Reset"); resetBtn.setToolTipText("Resets the properties to the defaults"); resetBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { setValues(defaultConfig); } }); JButton closeBtn = new JButton("Close"); closeBtn.setToolTipText("Closes the dialog. The last applied settings are kept."); closeBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { AbstractCodingOptionsDialog.this.dispose(); } }); setJMenuBar(new CodingDialogMenuBar(this, propsHolder, fcf, applyListener)); JComponent form = buildForm(propsHolder.getProperties(codingType)); form.setMaximumSize(FORM_PANEL_MAXIMUM_SIZE); form.setMinimumSize(FORM_PANEL_MINIMUM_SIZE); add(form, "span,grow,wrap"); JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(applyBtn); buttonPanel.add(resetBtn); add(buttonPanel); setIconImage(MapViewerGui.OPENLR_ICON); setLocationRelativeTo(null); pack(); }