List of usage examples for javax.swing JComponent getPreferredSize
@Transient
public Dimension getPreferredSize()
preferredSize
has been set to a non-null
value just returns it. From source file:Main.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. *//*from ww w . j a va 2 s. c om*/ private static void createAndShowGUI() { // Create and set up the window. JFrame frame = new JFrame("ListDataEventDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create and set up the content pane. JComponent newContentPane = new Main(); newContentPane.setOpaque(true); // content panes must be opaque frame.setContentPane(newContentPane); // Don't let the content pane get too small. // (Works if the Java look and feel provides // the window decorations.) newContentPane.setMinimumSize(new Dimension(newContentPane.getPreferredSize().width, 100)); // Display the window. frame.pack(); frame.setVisible(true); }
From source file:ListDataEventDemo.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. *//*from w ww . j a va 2 s . c o m*/ private static void createAndShowGUI() { // Create and set up the window. JFrame frame = new JFrame("ListDataEventDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create and set up the content pane. JComponent newContentPane = new ListDataEventDemo(); newContentPane.setOpaque(true); // content panes must be opaque frame.setContentPane(newContentPane); // Don't let the content pane get too small. // (Works if the Java look and feel provides // the window decorations.) newContentPane.setMinimumSize(new Dimension(newContentPane.getPreferredSize().width, 100)); // Display the window. frame.pack(); frame.setVisible(true); }
From source file:Main.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. */// ww w.ja v a 2s . c om private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame("ListDataEventDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. JComponent newContentPane = new Main(); newContentPane.setOpaque(true); //content panes must be opaque frame.setContentPane(newContentPane); //Don't let the content pane get too small. //(Works if the Java look and feel provides //the window decorations.) newContentPane.setMinimumSize(new Dimension(newContentPane.getPreferredSize().width, 100)); //Display the window. frame.pack(); frame.setVisible(true); }
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 ww w. ja va 2 s .c om*/ 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:com.projity.pm.graphic.chart.TimeChartPanel.java
public void configureScrollPaneHeaders(JScrollPane scrollPane, JComponent rowHeader) { viewport = scrollPane.getViewport(); if (viewport == null || viewport.getView() != this) return;/* w ww .ja v a2s.com*/ JViewport vp = new JViewport(); vp.setView(rowHeader); vp.setPreferredSize(rowHeader.getPreferredSize()); scrollPane.setRowHeader(vp); scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, new ChartCorner(this)); Border border = scrollPane.getBorder(); if (border == null || border instanceof UIResource) { scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder")); } // left scale synchro viewport.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { updateTimeScaleComponentSize(); } }); }
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; }//ww w . j a va 2s . 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: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 .ja va2 s.co m*/ 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 ww . jav a2 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:de.erdesignerng.visual.jgraph.JGraphEditor.java
private void performRadialLayout() { Model theModel = graph.getDBModel(); List<Set<Table>> theLayers = buildHierarchy(theModel); int centerx = 500 * (theLayers.size() + 1); int centery = 500 * (theLayers.size() + 1); int theRadius = 0; for (int theLayer = theLayers.size() - 1; theLayer >= 0; theLayer--) { Set<Table> theLayerTables = theLayers.get(theLayer); if (theLayerTables.size() > 0) { TableCellView.MyRenderer theRenderer = new TableCellView.MyRenderer(); double thePerimeter = 0; double theMinRadius = 0; for (Table theTable : theLayerTables) { JComponent theRendererComponent = theRenderer.getRendererComponent(theTable); Dimension theSize = theRendererComponent.getPreferredSize(); double theR = Math.sqrt(theSize.width * theSize.width + theSize.height * theSize.height); thePerimeter += theR;/*w w w .j av a2s . c o m*/ theMinRadius = Math.max(theMinRadius, theR); } thePerimeter += theLayerTables.size() * 40; double theRadiusIncrement = (thePerimeter / (Math.PI * 2)) - theRadius; theRadius += Math.max(theRadiusIncrement, theMinRadius); double theIncrement = Math.toDegrees(360 / theLayerTables.size()); double theAngle = 0; for (Table theTable : theLayerTables) { int theXP = centerx + (int) (Math.cos(theAngle) * theRadius); int theYP = centery + (int) (Math.sin(theAngle) * theRadius); theTable.getProperties().setPointProperty(Table.PROPERTY_LOCATION, theXP, theYP); theAngle += theIncrement; } theRadius += 500; } } if (theModel.getViews().size() > 0) { double theIncrement = Math.toDegrees(360 / theModel.getViews().size()); double theAngle = 0; for (View theView : theModel.getViews()) { int theXP = centerx + (int) (Math.cos(theAngle) * theRadius); int theYP = centery + (int) (Math.sin(theAngle) * theRadius); theView.getProperties().setPointProperty(View.PROPERTY_LOCATION, theXP, theYP); theAngle += theIncrement; } } updatePositions(); repaintGraph(); }
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. */// www . j a va2 s .co 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); }