List of usage examples for javax.swing JLabel setVerticalAlignment
@BeanProperty(visualUpdate = true, enumerationValues = { "SwingConstants.TOP", "SwingConstants.CENTER", "SwingConstants.BOTTOM" }, description = "The alignment of the label's contents along the Y axis.") public void setVerticalAlignment(int alignment)
From source file:LayeredPaneDemo.java
private JLabel createColoredLabel(String text, Color color, Point origin) { JLabel label = new JLabel(text); label.setVerticalAlignment(JLabel.TOP); label.setHorizontalAlignment(JLabel.CENTER); label.setOpaque(true);// w w w. j a va 2s .c om label.setBackground(color); label.setForeground(Color.black); label.setBorder(BorderFactory.createLineBorder(Color.black)); label.setBounds(origin.x, origin.y, 140, 140); return label; }
From source file:components.LayeredPaneDemo2.java
private JLabel createColoredLabel(String text, Color color) { JLabel label = new JLabel(text); label.setVerticalAlignment(JLabel.TOP); label.setHorizontalAlignment(JLabel.CENTER); label.setOpaque(true);//from w w w. j a v a 2 s.co m label.setBackground(color); label.setForeground(Color.black); label.setBorder(BorderFactory.createLineBorder(Color.black)); label.setPreferredSize(new Dimension(140, 140)); return label; }
From source file:kuvalataaja.user_interface.GUI.java
/** * Creates a label to keep the rest of the code cleaner. * @return The created label //from w w w. j a v a 2 s. c o m */ private JLabel createJLabel() { JLabel label = new JLabel(); label.setText("<html><p>Hello and welcome to my program!</p></html>"); label.setHorizontalAlignment(JLabel.CENTER); label.setVerticalAlignment(JLabel.CENTER); return label; }
From source file:com.intel.stl.ui.main.view.StaDetailsPanel.java
private JLabel createNameLabel(String name) { JLabel label = ComponentFactory.getH5Label(name, Font.PLAIN); label.setVerticalAlignment(JLabel.BOTTOM); return label; }
From source file:com.od.jtimeseries.ui.visualizer.chart.TimeSeriesChart.java
private void createNoChartsPanel() { noChartsPanel.setLayout(new BorderLayout()); JLabel noSeriesLabel = new JLabel("No Timeseries Selected"); noSeriesLabel.setHorizontalAlignment(JLabel.CENTER); noSeriesLabel.setVerticalAlignment(JLabel.CENTER); noChartsPanel.add(noSeriesLabel);/* w w w . j a va 2s . c o m*/ }
From source file:com.openbravo.pos.util.ThumbNailBuilder.java
public Image getThumbNailText(Image img, String text) { /*/*from w w w . ja v a 2 s . co m*/ * 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:com.intel.stl.ui.main.view.StaDetailsPanel.java
private JLabel createNumberLabel() { JLabel label = ComponentFactory.getH4Label(STLConstants.K0039_NOT_AVAILABLE.getValue(), Font.PLAIN); label.setHorizontalAlignment(JLabel.RIGHT); label.setVerticalAlignment(JLabel.BOTTOM); return label; }
From source file:Main.java
public Main() { for (int i = 0; i < panels.length; i++) { final String[] labels = new String[] { "0", "1" }; final Random rand = new Random(); int index = rand.nextInt(labels.length); String randomTitle = labels[index]; final JLabel label = new JLabel(randomTitle, JLabel.CENTER); Timer lblt = new Timer(00, new ActionListener() { @Override// w ww. ja va 2s . co m public void actionPerformed(ActionEvent ae) { label.setText(labels[rand.nextInt(labels.length)]); } }); lblt.setRepeats(true); lblt.start(); label.setForeground(Color.green); label.setVerticalAlignment(JLabel.CENTER); panels[i] = new JPanel(); panels[i].setBackground(Color.BLACK); panels[i].add(label); frame.getContentPane().add(panels[i]); } frame.setLayout(new GridLayout(grid, grid)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH); frame.setVisible(true); ActionListener action = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (int i = 0; i < panels.length; i++) { Color mix = new Color(255, 255, 255); Random random = new Random(); int r = random.nextInt(255); int g = random.nextInt(255); int b = random.nextInt(255); if (mix != null) { r = (r + mix.getRed()) / 2; g = (g + mix.getGreen()) / 2; b = (b + mix.getBlue()) / 2; } Color color = new Color(r, g, b); panels[i].setBackground(color); } } }; t = new Timer(00, action); t.setRepeats(true); t.start(); }
From source file:de.codesourcery.flocking.ui.NumberInputField.java
/** * Create instance./*from w w w . jav a 2s . co m*/ * * <p>Creates a resizable panel that holds a label, a textfield and a slider * for entering/adjusting a numeric value.</p> * * @param label the label to display * @param model the model that is used to read/write the value to be edited. If the model returns <code>null</code> values, * these will be treated as "0" (or "0.0" respectively). * @param minValue valid minimum value (inclusive) the user may enter * @param maxValue vali maximum value (inclusive) the user may enter * @param onlyIntValues whether the user may enter only integers or integers <b>and</b> floating-point numbers. */ public NumberInputField(String label, IModel<T> model, double minValue, double maxValue, final boolean onlyIntValues) { if (model == null) { throw new IllegalArgumentException("model must not be NULL."); } this.model = model; this.minValue = minValue; this.maxValue = maxValue; this.onlyIntValues = onlyIntValues; textField = new JTextField("0"); textField.setColumns(5); textField.setHorizontalAlignment(JTextField.RIGHT); slider = new JSlider(0, SLIDER_RESOLUTION); textField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (selfTriggeredEvent) { return; } final String s = textField.getText(); if (!StringUtils.isBlank(s)) { Number number = null; try { if (onlyIntValues) { number = Long.parseLong(s.trim()); } else { number = Double.parseDouble(s.trim()); } } catch (Exception ex) { textField.setText(numberToString(NumberInputField.this.model.getObject())); return; } updateModelValue(number); } } }); textField.setText(numberToString(model.getObject())); slider.getModel().setValue(calcSliderValue(model.getObject())); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (selfTriggeredEvent) { return; } final double percentage = slider.getModel().getValue() / (double) SLIDER_RESOLUTION; // 0...1 final double range = Math.abs(NumberInputField.this.maxValue - NumberInputField.this.minValue); final double newValue = NumberInputField.this.minValue + range * percentage; updateModelValue(newValue); } }); slider.setMinimumSize(new Dimension(100, 20)); slider.setPreferredSize(new Dimension(100, 20)); // do layout setLayout(new GridBagLayout()); GridBagConstraints cnstrs = new GridBagConstraints(); cnstrs.fill = GridBagConstraints.NONE; cnstrs.weightx = 0; cnstrs.weighty = 0; cnstrs.gridx = 0; cnstrs.gridy = 0; final JLabel l = new JLabel(label); l.setMinimumSize(new Dimension(1500, 20)); l.setPreferredSize(new Dimension(150, 20)); l.setVerticalAlignment(SwingConstants.TOP); add(l, cnstrs); cnstrs = new GridBagConstraints(); cnstrs.fill = GridBagConstraints.NONE; cnstrs.weightx = 0; cnstrs.weighty = 0; cnstrs.gridx = 1; cnstrs.gridy = 0; cnstrs.insets = new Insets(0, 0, 0, 10); add(textField, cnstrs); cnstrs = new GridBagConstraints(); cnstrs.fill = GridBagConstraints.HORIZONTAL; cnstrs.weightx = 1.0; cnstrs.weighty = 1.0; cnstrs.gridx = 2; cnstrs.gridy = 0; add(slider, cnstrs); }
From source file:de.tbuchloh.kiskis.gui.SecuredElementView.java
private Component createMainTab() { final JPanel textFields = new JPanel(new SpringLayout()); textFields.setBorder(LnFHelper.createDefaultBorder()); final JLabel nameLabel = LnFHelper.createLabel(M.getString("name_label")); //$NON-NLS-1$ nameLabel.setVerticalAlignment(SwingConstants.TOP); nameLabel.setLabelFor(_name);// w w w . j a va 2 s. c o m textFields.add(nameLabel); textFields.add(_name); final JLabel pwdLabel = LnFHelper.createLabel(M.getString("password_label")); //$NON-NLS-1$ pwdLabel.setVerticalAlignment(SwingConstants.TOP); pwdLabel.setLabelFor(_pwdField); textFields.add(pwdLabel); textFields.add(_pwdField); final JPanel datePanel = new JPanel(); final GridBagBuilder builder = new GridBagBuilder(datePanel); builder.setAlignment(GridBagConstraints.NORTHWEST); builder.add(_dateField); builder.add(_neverBox); builder.setFill(GridBagConstraints.NONE); builder.setAlignment(GridBagConstraints.EAST); builder.addLast(_historyLink); builder.setFill(GridBagConstraints.BOTH); builder.setAlignment(GridBagConstraints.NORTHWEST); final JLabel expiresLabel = LnFHelper.createLabel(M.getString("expires_label")); //$NON-NLS-1$ expiresLabel.setVerticalAlignment(SwingConstants.TOP); expiresLabel.setLabelFor(datePanel); textFields.add(expiresLabel); textFields.add(datePanel); SpringUtilities.makeCompactGrid(textFields, 3, 2, 5, 5, 5, 5); return textFields; }