List of usage examples for javax.swing JLabel getPreferredSize
@Transient
public Dimension getPreferredSize()
preferredSize
has been set to a non-null
value just returns it. From source file:net.sf.firemox.ui.component.SplashScreen.java
/** * Create a new instance of this class.//from w w w .ja va 2 s. c o m * * @param filename * the picture filename. * @param parent * the splash screen's parent. * @param waitTime * the maximum time before the screen is hidden. */ public SplashScreen(String filename, Frame parent, int waitTime) { super(parent); getContentPane().setLayout(null); toFront(); final JLabel l = new JLabel(new ImageIcon(filename)); final Dimension labelSize = l.getPreferredSize(); l.setLocation(0, 0); l.setSize(labelSize); setSize(labelSize); final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setLocation(screenSize.width / 2 - labelSize.width / 2, screenSize.height / 2 - labelSize.height / 2); final JLabel mp = new JLabel(IdConst.PROJECT_DISPLAY_NAME); mp.setLocation(30, 305); mp.setSize(new Dimension(300, 30)); final JLabel version = new JLabel(IdConst.VERSION); version.setLocation(235, 418); version.setSize(new Dimension(300, 30)); final JTextArea disclaimer = new JTextArea(); disclaimer.setEditable(false); disclaimer.setLineWrap(true); disclaimer.setWrapStyleWord(true); disclaimer.setAutoscrolls(true); disclaimer.setFont(MToolKit.defaultFont); disclaimer.setTabSize(2); // Then try and read it locally Reader inGPL = null; try { inGPL = new BufferedReader(new InputStreamReader(MToolKit.getResourceAsStream(IdConst.FILE_LICENSE))); disclaimer.read(inGPL, ""); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(inGPL); } final JScrollPane disclaimerSPanel = new JScrollPane(); disclaimerSPanel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); disclaimerSPanel.setViewportView(disclaimer); disclaimerSPanel.setLocation(27, 340); disclaimerSPanel.setPreferredSize(new Dimension(283, 80)); disclaimerSPanel.setSize(disclaimerSPanel.getPreferredSize()); getContentPane().add(disclaimerSPanel); getContentPane().add(version); getContentPane().add(mp); getContentPane().add(l); final int pause = waitTime; final Runnable waitRunner = new Runnable() { public void run() { try { Thread.sleep(pause); while (!bKilled) { Thread.sleep(200); } } catch (InterruptedException e) { // Ignore this error } setVisible(false); dispose(); MagicUIComponents.magicForm.toFront(); } }; // setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { setVisible(false); dispose(); if (MagicUIComponents.magicForm != null) MagicUIComponents.magicForm.toFront(); } }); addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { setVisible(false); dispose(); MagicUIComponents.magicForm.toFront(); } } }); setVisible(true); start(waitRunner); }
From source file:com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel.java
private JComponent buildToolbar() { JXToolBar toolBar = UISupport.createToolbar(); JButton runButton = UISupport.createToolbarButton(runAction); toolBar.add(runButton);//from w w w. ja va 2 s .c o m toolBar.add(Box.createHorizontalGlue()); JLabel label = new JLabel("<html>Script is invoked with <code>log</code>, <code>context</code> " + "and <code>testRunner</code> variables</html>"); label.setToolTipText(label.getText()); label.setMaximumSize(label.getPreferredSize()); toolBar.add(label); toolBar.addRelatedGap(); toolBar.add(UISupport.createToolbarButton(new ShowOnlineHelpAction(HelpUrls.GROOVYSTEPEDITOR_HELP_URL))); componentEnabler.add(runButton); return toolBar; }
From source file:com.openbravo.pos.util.ThumbNailBuilder.java
public Image getThumbNailText(Image img, String text) { /*/*from w w w .j a v a2 s . com*/ * Create an image containing a thumbnail of the product image, * or default image. * * Then apply the text of the product name. Use text wrapping. * * If the product name is too big for the label, ensure that * the first part is displayed. */ img = getThumbNail(img); BufferedImage imgtext = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = imgtext.createGraphics(); // The text // <p style="width: 100px"> DOES NOT WORK PROPERLY. // use width= instead. String html = "<html><p style=\"text-align:center\" width=\"" + imgtext.getWidth() + "\">" + StringEscapeUtils.escapeHtml(text) + "</p>"; JLabel label = new JLabel(html); label.setOpaque(false); //label.setText("<html><center>Line1<br>Line2"); label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); label.setVerticalAlignment(javax.swing.SwingConstants.TOP); Dimension d = label.getPreferredSize(); label.setBounds(0, 0, imgtext.getWidth(), d.height); // The background Color c1 = new Color(0xff, 0xff, 0xff, 0x40); Color c2 = new Color(0xff, 0xff, 0xff, 0xd0); // Point2D center = new Point2D.Float(imgtext.getWidth() / 2, label.getHeight()); // float radius = imgtext.getWidth() / 3; // float[] dist = {0.1f, 1.0f}; // Color[] colors = {c2, c1}; // Paint gpaint = new RadialGradientPaint(center, radius, dist, colors); Paint gpaint = new GradientPaint(new Point(0, 0), c1, new Point(label.getWidth() / 2, 0), c2, true); g2d.drawImage(img, 0, 0, null); int ypos = imgtext.getHeight() - label.getHeight(); int ypos_min = -4; // todo: configurable if (ypos < ypos_min) ypos = ypos_min; // Clamp label g2d.translate(0, ypos); g2d.setPaint(gpaint); g2d.fillRect(0, 0, imgtext.getWidth(), label.getHeight()); label.paint(g2d); g2d.dispose(); return imgtext; }
From source file:net.sf.jabref.gui.mergeentries.MergeEntries.java
/** * Main function for building the merge entry JPanel *///from w ww .ja v a 2s.co m private void initialize() { doneBuilding = false; setupFields(); // Fill diff mode combo box for (String diffText : DIFF_MODES) { diffMode.addItem(diffText); } diffMode.setSelectedIndex(Math.min(Globals.prefs.getInt(JabRefPreferences.MERGE_ENTRIES_DIFF_MODE), diffMode.getItemCount() - 1)); diffMode.addActionListener(e -> { updateTextPanes(differentFields); storePreference(); }); // Create main layout String colSpecMain = "left:pref, 5px, center:3cm:grow, 5px, center:pref, 3px, center:pref, 3px, center:pref, 5px, center:3cm:grow"; String colSpecMerge = "left:pref, 5px, fill:3cm:grow, 5px, center:pref, 3px, center:pref, 3px, center:pref, 5px, fill:3cm:grow"; String rowSpec = "pref, pref, 10px, fill:5cm:grow, 10px, pref, 10px, fill:3cm:grow"; StringBuilder rowBuilder = new StringBuilder(""); for (int i = 0; i < allFields.size(); i++) { rowBuilder.append("pref, 2dlu, "); } rowBuilder.append("pref"); JPanel mergePanel = new JPanel(); FormLayout mainLayout = new FormLayout(colSpecMain, rowSpec); FormLayout mergeLayout = new FormLayout(colSpecMerge, rowBuilder.toString()); mainPanel.setLayout(mainLayout); mergePanel.setLayout(mergeLayout); CellConstraints cc = new CellConstraints(); mainPanel.add(boldFontLabel(Localization.lang("Use")), cc.xyw(4, 1, 7, "center, bottom")); mainPanel.add(diffMode, cc.xy(11, 1, "right, bottom")); // Set headings JLabel[] headingLabels = new JLabel[6]; for (int i = 0; i < 6; i++) { headingLabels[i] = boldFontLabel(COLUMN_HEADINGS[i]); mainPanel.add(headingLabels[i], cc.xy(1 + (i * 2), 2)); } mainPanel.add(new JSeparator(), cc.xyw(1, 3, 11)); // Start with entry type mergePanel.add(boldFontLabel(Localization.lang("Entry type")), cc.xy(1, 1)); JTextPane leftTypeDisplay = getStyledTextPane(); leftTypeDisplay.setText(HTML_START + leftEntry.getType() + HTML_END); mergePanel.add(leftTypeDisplay, cc.xy(3, 1)); if (leftEntry.getType().equals(rightEntry.getType())) { identicalTypes = true; } else { identicalTypes = false; ButtonGroup group = new ButtonGroup(); typeRadioButtons = new ArrayList<>(2); for (int k = 0; k < 3; k += 2) { JRadioButton button = new JRadioButton(); typeRadioButtons.add(button); group.add(button); mergePanel.add(button, cc.xy(5 + (k * 2), 1)); button.addChangeListener(e -> updateAll()); } typeRadioButtons.get(0).setSelected(true); } JTextPane rightTypeDisplay = getStyledTextPane(); rightTypeDisplay.setText(HTML_START + rightEntry.getType() + HTML_END); mergePanel.add(rightTypeDisplay, cc.xy(11, 1)); // For all fields in joint add a row and possibly radio buttons int row = 2; int maxLabelWidth = -1; for (String field : allFields) { JLabel label = boldFontLabel(new SentenceCaseFormatter().format(field)); mergePanel.add(label, cc.xy(1, (2 * row) - 1, "left, top")); Optional<String> leftString = leftEntry.getFieldOptional(field); Optional<String> rightString = rightEntry.getFieldOptional(field); if (leftString.equals(rightString)) { identicalFields.add(field); } else { differentFields.add(field); } maxLabelWidth = Math.max(maxLabelWidth, label.getPreferredSize().width); // Left text pane if (leftString.isPresent()) { JTextPane tf = getStyledTextPane(); mergePanel.add(tf, cc.xy(3, (2 * row) - 1, "f, f")); leftTextPanes.put(field, tf); } // Add radio buttons if the two entries do not have identical fields if (identicalFields.contains(field)) { mergedEntry.setField(field, leftString.get()); // Will only happen if both entries have the field and the content is identical } else { ButtonGroup group = new ButtonGroup(); List<JRadioButton> list = new ArrayList<>(3); for (int k = 0; k < 3; k++) { JRadioButton button = new JRadioButton(); group.add(button); mergePanel.add(button, cc.xy(5 + (k * 2), (2 * row) - 1)); button.addChangeListener(e -> updateAll()); list.add(button); } radioButtons.put(field, list); if (leftString.isPresent()) { list.get(0).setSelected(true); if (!rightString.isPresent()) { list.get(2).setEnabled(false); } } else { list.get(0).setEnabled(false); list.get(2).setSelected(true); } } // Right text pane if (rightString.isPresent()) { JTextPane tf = getStyledTextPane(); mergePanel.add(tf, cc.xy(11, (2 * row) - 1, "f, f")); rightTextPanes.put(field, tf); } row++; } scrollPane = new JScrollPane(mergePanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setBorder(BorderFactory.createEmptyBorder()); updateTextPanes(allFields); mainPanel.add(scrollPane, cc.xyw(1, 4, 11)); mainPanel.add(new JSeparator(), cc.xyw(1, 5, 11)); // Synchronize column widths String[] rbAlign = { "right", "center", "left" }; mainLayout.setColumnSpec(1, ColumnSpec.decode(Integer.toString(maxLabelWidth) + "px")); Integer maxRBWidth = -1; for (int k = 2; k < 5; k++) { maxRBWidth = Math.max(maxRBWidth, headingLabels[k].getPreferredSize().width); } for (int k = 0; k < 3; k++) { mergeLayout.setColumnSpec(5 + (k * 2), ColumnSpec.decode(rbAlign[k] + ":" + maxRBWidth + "px")); } // Setup a PreviewPanel and a Bibtex source box for the merged entry mainPanel.add(boldFontLabel(Localization.lang("Merged entry")), cc.xyw(1, 6, 6)); entryPreview = new PreviewPanel(null, mergedEntry, null, Globals.prefs.get(JabRefPreferences.PREVIEW_0)); mainPanel.add(entryPreview, cc.xyw(1, 8, 6)); mainPanel.add(boldFontLabel(Localization.lang("Merged BibTeX source code")), cc.xyw(8, 6, 4)); sourceView = new JTextArea(); sourceView.setLineWrap(true); sourceView.setFont(new Font("Monospaced", Font.PLAIN, Globals.prefs.getInt(JabRefPreferences.FONT_SIZE))); mainPanel.add(new JScrollPane(sourceView), cc.xyw(8, 8, 4)); sourceView.setEditable(false); // Add some margin around the layout mainLayout.appendRow(RowSpec.decode(MARGIN)); mainLayout.appendColumn(ColumnSpec.decode(MARGIN)); mainLayout.insertRow(1, RowSpec.decode(MARGIN)); mainLayout.insertColumn(1, ColumnSpec.decode(MARGIN)); // Everything done, allow any action to actually update the merged entry doneBuilding = true; updateAll(); // Show what we've got mainPanel.setVisible(true); javax.swing.SwingUtilities.invokeLater(() -> scrollPane.getVerticalScrollBar().setValue(0)); }
From source file:edu.ku.brc.specify.tasks.subpane.security.SecurityAdminPane.java
/** * //from w w w . j a va 2 s . c o m */ private void createNavigationTree() { TreeSelectionListener tsl = new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent tse) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null || !(node.getUserObject() instanceof DataModelObjBaseWrapper)) { // Nothing is selected or object type isn't relevant clearPanels(); return; } // ask if user he wants to discard changes if that's the case if (!aboutToShutdown()) { clearPanels(); return; } DataModelObjBaseWrapper dataWrp = (DataModelObjBaseWrapper) (node.getUserObject()); // get parent if it is a user /*DataModelObjBaseWrapper userObjWrp = null; DataModelObjBaseWrapper groupObjWrp = null; DataModelObjBaseWrapper collectionWrp = null; Object dataObj = dataWrp.getDataObj(); if (dataObj instanceof SpecifyUser) { // XXX Also might need to check to see if anyone is logged into the Group // when editing a Group SpecifyUser currentUser = AppContextMgr.getInstance().getClassObject(SpecifyUser.class); SpecifyUser spUser = (SpecifyUser)dataObj; if (!spUser.getIsLoggedIn() || currentUser.getId().equals(spUser.getId())) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); userObjWrp = (DataModelObjBaseWrapper) node.getUserObject(); groupObjWrp = (DataModelObjBaseWrapper) parent.getUserObject(); collectionWrp = (DataModelObjBaseWrapper) ((DefaultMutableTreeNode)parent.getParent()).getUserObject(); } else { UIRegistry.showLocalizedError("SecuirytAdminPane.USR_IS_ON", spUser.getName()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { tree.clearSelection(); } }); return; } } nodesDiscipline = navTreeMgr.getParentOfClass(node, Discipline.class); nodesDivision = nodesDiscipline != null ? nodesDiscipline.getDivision() : null; showInfoPanel(dataWrp, userObjWrp, groupObjWrp, collectionWrp, node.toString()); updateUIEnabled(dataWrp);*/ // get parent if it is a user DataModelObjBaseWrapper secondObjWrp = null; DataModelObjBaseWrapper collectionWrp = null; Object dataObj = dataWrp.getDataObj(); if (dataObj instanceof SpecifyUser) { // XXX Also might need to check to see if anyone is logged into the Group // when editing a Group SpecifyUser currentUser = AppContextMgr.getInstance().getClassObject(SpecifyUser.class); SpecifyUser spUser = (SpecifyUser) dataObj; if (!spUser.getIsLoggedIn() || currentUser.getId().equals(spUser.getId())) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); secondObjWrp = (DataModelObjBaseWrapper) parent.getUserObject(); collectionWrp = (DataModelObjBaseWrapper) ((DefaultMutableTreeNode) parent.getParent()) .getUserObject(); } else { UIRegistry.showLocalizedError("SecuirytAdminPane.USR_IS_ON", spUser.getName()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { tree.clearSelection(); } }); return; } } nodesDiscipline = navTreeMgr.getParentOfClass(node, Discipline.class); nodesDivision = nodesDiscipline != null ? nodesDiscipline.getDivision() : null; showInfoPanel(dataWrp, secondObjWrp, collectionWrp, node.toString()); updateUIEnabled(dataWrp); } }; DefaultTreeModel model = createNavigationTreeModel(); tree = new JTree(model); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setRootVisible(false); tree.setCellRenderer(new MyTreeCellRenderer()); tree.addTreeSelectionListener(tsl); // Expand the tree for (int i = 0; i < tree.getRowCount(); i++) { tree.expandRow(i); } for (int i = tree.getRowCount() - 1; i >= 1; i--) { if (tree.getPathForRow(i).getPathCount() > 3) { tree.collapseRow(i); } } navTreeMgr = new NavigationTreeMgr(tree, spUsers); // create object that will control the creation of popups // constructor will take care of hooking up right listeners to the tree. navTreeContextMgr = new NavigationTreeContextMenuMgr(navTreeMgr); IconManager.IconSize iconSize = IconManager.IconSize.Std20; ImageIcon sysIcon = IconManager.getIcon("SystemSetup", iconSize); JLabel label = createLabel("XXXX"); label.setIcon(sysIcon); label.setBorder(BorderFactory.createEmptyBorder(1, 0, 0, 0)); tree.setRowHeight(label.getPreferredSize().height); // Why doesn't this work? SwingUtilities.invokeLater(new Runnable() { @Override public void run() { tree.expandRow(1); } }); //expandAll(tree, true); }
From source file:display.containers.FileManager.java
private void setColumnWidth(int column, int width) { TableColumn tableColumn = table.getColumnModel().getColumn(column); if (width < 0) { // use the preferred width of the header.. JLabel label = new JLabel((String) tableColumn.getHeaderValue()); Dimension preferred = label.getPreferredSize(); // altered 10->14 as per camickr comment. width = (int) preferred.getWidth() + 14; }/*from w ww. j a v a 2s . c om*/ tableColumn.setPreferredWidth(width); tableColumn.setMaxWidth(width); tableColumn.setMinWidth(width); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopFieldGroup.java
protected void reattachColumnFields(int colIndex) { fields.values().stream().filter(FieldConfig::isBound).map(fieldConfig -> ((FieldConfigImpl) fieldConfig)) .filter(fci -> fci.getColumn() == colIndex).forEach(fci -> { impl.remove(fci.getCompositionNN().getComposition()); if (fci.getLabel() != null) { impl.remove(fci.getLabel()); }// w w w. jav a2s . c o m if (fci.getToolTipButton() != null) { impl.remove(fci.getToolTipButton()); } }); List<FieldConfig> columnFCs = columnFieldMapping.get(colIndex); int insertRowIndex = 0; for (FieldConfig fc : columnFCs) { if (fc.isBound()) { FieldConfigImpl fci = (FieldConfigImpl) fc; Component fieldComponent = fci.getComponentNN(); JComponent composition = fieldComponent.unwrapComposition(JComponent.class); JLabel label = fci.getLabel(); if (label != null) { int preferredCaptionWidth = getPreferredCaptionWidth(colIndex); if (preferredCaptionWidth > 0) { label.setPreferredSize(new Dimension(preferredCaptionWidth, 25)); label.setMaximumSize(new Dimension(preferredCaptionWidth, 25)); label.setMinimumSize(new Dimension(preferredCaptionWidth, 25)); } else { label.setPreferredSize(new Dimension(label.getPreferredSize().width, 25)); } label.setVisible(fieldComponent.isVisible()); CC labelCc = new CC(); MigLayoutHelper.applyAlignment(labelCc, Alignment.TOP_LEFT); impl.add(label, labelCc.cell(colIndex * 3, insertRowIndex, 1, 1)); } ToolTipButton toolTipButton = fci.getToolTipButton(); if (fci.getToolTipButton() != null) { updateTooltipButton(fci, fieldComponent); DesktopToolTipManager.getInstance().registerTooltip(toolTipButton); impl.add(toolTipButton, new CC().cell(colIndex * 3 + 2, insertRowIndex, 1, 1).alignY("top")); } CC cell = new CC().cell(colIndex * 3 + 1, insertRowIndex, 1, 1); MigLayoutHelper.applyWidth(cell, (int) fieldComponent.getWidth(), fieldComponent.getWidthUnits(), false); MigLayoutHelper.applyHeight(cell, (int) fieldComponent.getHeight(), fieldComponent.getHeightUnits(), false); MigLayoutHelper.applyAlignment(cell, fieldComponent.getAlignment()); composition.putClientProperty(getSwingPropertyId(), fci.getId()); impl.add(composition, cell); insertRowIndex++; } } impl.validate(); impl.repaint(); }
From source file:com.osparking.attendant.AttListForm.java
private void initComponentsUser() { String idStr = USER_ID_LABEL.getContent() + loginID; JLabel tempLabel = new JLabel(idStr); tempLabel.setFont(topUserIdLabel.getFont()); Dimension dim = tempLabel.getPreferredSize(); topUserIdLabel.setText(idStr);/*from w ww . j av a2s. c o m*/ topUserIdLabel.setPreferredSize(new Dimension(dim.width + 15, dim.height + 6)); topUserIdLabel.setSize(new Dimension(dim.width, dim.height)); adminAuth2CheckBox.setSelected(isManager); saveFileChooser.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG); SetTableColumnWidth(); setModificationState(false); }
From source file:net.team2xh.crt.gui.util.GUIToolkit.java
/** * Displays a dialog with "OK" button.//from www. ja va 2 s . c o m * * @param parent Parent window * @param message Message (can contain "\n" characters) * @param title Dialog title * @param type Icon type (use JOptionPane static values) */ public static void showOkDialog(java.awt.Window parent, String message, String title, int type) { SwingUtilities.invokeLater(() -> { Object[] options = { "OK" }; JLabel msg = new JLabel(convertToMultiline(message)); Dimension sz = msg.getPreferredSize(); msg.setPreferredSize(new Dimension(sz.width + 20, sz.height)); JOptionPane.showOptionDialog(parent, msg, title, JOptionPane.DEFAULT_OPTION, type, null, options, options[0]); }); }