List of usage examples for javax.swing JLabel setLabelFor
@BeanProperty(description = "The component this is labelling.") public void setLabelFor(Component c)
From source file:Main.java
public static JLabel createLabel(String text, Component labelFor) { JLabel result = new JLabel(text); if (labelFor != null) { result.setLabelFor(labelFor); }// w w w . j a v a 2 s .c o m return result; }
From source file:Main.java
public static JLabel createSAFLabel(final String name, final JComponent labelForComponent) { JLabel label = new JLabel(); label.setName(name);/*from w w w.j a v a2 s . c o m*/ if (labelForComponent != null) { label.setLabelFor(labelForComponent); } return label; }
From source file:Main.java
private static JSpinner addLabeledSpinner(String label, SpinnerModel model, boolean b) { JLabel l = new JLabel(label); //c.add(l);//from w w w .j a va 2 s . c o m JSpinner spinner = new JSpinner(model); l.setLabelFor(spinner); //c.add(spinner); return spinner; }
From source file:Main.java
/** * Creates a <code>JSpinner</code> with the specified label text from the given * <code>SpinnerModel</code> and adds the <code>JSpinner</code> to the given * <code>Container</code>.// w w w . ja v a 2 s. co m * @param c - the container to add the spinner to * @param label - the text which to add to the spinner * @param model - the <code>SpinnerModel</code> to make the spinner from * @return a JSpinner created from the <code>SpinnerModel</code> with the * specified label text */ public static JSpinner addLabeledSpinner(Container c, String label, SpinnerModel model) { JLabel l = new JLabel(label); c.add(l); JSpinner spinner = new JSpinner(model); l.setLabelFor(spinner); c.add(spinner); return spinner; }
From source file:Main.java
/** * Creates a <code>JSpinner</code> with the specified label text from the given * <code>SpinnerModel</code> and adds the <code>JSpinner</code> to the given * <code>Container</code>. If the wrap parameter is set to true, MigLayout's * "wrap" attribute will be applied to the <code>JTextField</code>, meaning * the next component added will appear on the next line. * (Exception: Will not work if MigLayout's flowy layout constraint is applied, * but it is rarely used MigLayout feature and thus not a common concern; however * if you have set this layout constraint on your <code>JComponent</code> do not * attempt to use the wrap option of this method.) * @param c - the container to add the spinner to * @param label - the text which to add to the spinner * @param model - the <code>SpinnerModel</code> to make the spinner from * @param wrap - indicates whether the MigLayout "wrap" attribute should be * present when this <code>JSpinner</code> is added to the container; if * component does not have the MigLayout as it's layout manager then this * property has no effect// www . ja v a 2s .c om * @return a JSpinner created from the <code>SpinnerModel</code> with the * specified label text */ public static JSpinner addLabeledSpinner(Container c, String label, SpinnerModel model, boolean wrap) { JLabel l = new JLabel(label); c.add(l, "align left"); JSpinner spinner = new JSpinner(model); l.setLabelFor(spinner); if (wrap) { c.add(spinner, "align left, wrap"); } else { c.add(spinner, "align left, split"); } return spinner; }
From source file:components.SpinnerDemo.java
static protected JSpinner addLabeledSpinner(Container c, String label, SpinnerModel model) { JLabel l = new JLabel(label); c.add(l);/* www .j a v a 2 s . co m*/ JSpinner spinner = new JSpinner(model); l.setLabelFor(spinner); c.add(spinner); return spinner; }
From source file:components.ListDialogRunner.java
public static JPanel createUI() { //Create the labels. JLabel intro = new JLabel("The chosen name:"); final JLabel name = new JLabel(names[1]); intro.setLabelFor(name); //Use a wacky font if it exists. If not, this falls //back to a font we know exists. name.setFont(getAFont());/*from w w w .java 2 s .c o m*/ //Create the button. final JButton button = new JButton("Pick a new name..."); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String selectedName = ListDialog.showDialog(frame, button, "Baby names ending in O:", "Name Chooser", names, name.getText(), "Cosmo "); name.setText(selectedName); } }); //Create the panel we'll return and set up the layout. JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20)); intro.setAlignmentX(JComponent.CENTER_ALIGNMENT); name.setAlignmentX(JComponent.CENTER_ALIGNMENT); button.setAlignmentX(JComponent.CENTER_ALIGNMENT); //Add the labels to the content pane. panel.add(intro); panel.add(Box.createVerticalStrut(5)); //extra space panel.add(name); //Add a vertical spacer that also guarantees us a minimum width: panel.add(Box.createRigidArea(new Dimension(150, 10))); //Add the button. panel.add(button); return panel; }
From source file:SpringForm.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() { String[] labels = { "Name: ", "Fax: ", "Email: ", "Address: " }; int numPairs = labels.length; //Create and populate the panel. JPanel p = new JPanel(new SpringLayout()); for (int i = 0; i < numPairs; i++) { JLabel l = new JLabel(labels[i], JLabel.TRAILING); p.add(l); JTextField textField = new JTextField(10); l.setLabelFor(textField); p.add(textField); } //Lay out the panel. SpringUtilities.makeCompactGrid(p, numPairs, 2, //rows, cols 6, 6, //initX, initY 6, 6); //xPad, yPad //Create and set up the window. JFrame frame = new JFrame("SpringForm"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. p.setOpaque(true); //content panes must be opaque frame.setContentPane(p); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:TextForm.java
public TextForm(String[] labels, char[] mnemonics, int[] widths, String[] tips) { super(new BorderLayout()); JPanel labelPanel = new JPanel(new GridLayout(labels.length, 1)); JPanel fieldPanel = new JPanel(new GridLayout(labels.length, 1)); add(labelPanel, BorderLayout.WEST); add(fieldPanel, BorderLayout.CENTER); fields = new JTextField[labels.length]; for (int i = 0; i < labels.length; i += 1) { fields[i] = new JTextField(); if (i < tips.length) fields[i].setToolTipText(tips[i]); if (i < widths.length) fields[i].setColumns(widths[i]); JLabel lab = new JLabel(labels[i], JLabel.RIGHT); lab.setLabelFor(fields[i]); if (i < mnemonics.length) lab.setDisplayedMnemonic(mnemonics[i]); labelPanel.add(lab);/* w ww . j a va 2 s . c om*/ JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT)); p.add(fields[i]); fieldPanel.add(p); } }
From source file:components.PasswordDemo.java
public PasswordDemo(JFrame f) { //Use the default FlowLayout. controllingFrame = f;/* w w w . jav a 2s. c o m*/ //Create everything. passwordField = new JPasswordField(10); passwordField.setActionCommand(OK); passwordField.addActionListener(this); JLabel label = new JLabel("Enter the password: "); label.setLabelFor(passwordField); JComponent buttonPane = createButtonPanel(); //Lay out everything. JPanel textPane = new JPanel(new FlowLayout(FlowLayout.TRAILING)); textPane.add(label); textPane.add(passwordField); add(textPane); add(buttonPane); }