Java Code Examples for javax.swing.JLabel#setName()

The following examples show how to use javax.swing.JLabel#setName() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: testing-cin   File: Calculator.java    License: MIT License 6 votes vote down vote up
public Calculator() {
    super("Calculator");
 
    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel numberPanel = buildNumberPanel();
    JPanel operatorPanel = buildOperatorPanel();
    JPanel clearPanel = buildClearPanel();
    lcdDisplay = new JTextArea();
    lcdDisplay.setName("lcd");
    lcdDisplay.setFont(new Font("Dialog", Font.BOLD, 18));
    mainPanel.add(clearPanel, BorderLayout.SOUTH);
    mainPanel.add(numberPanel, BorderLayout.CENTER);
    mainPanel.add(operatorPanel, BorderLayout.EAST);
    mainPanel.add(lcdDisplay, BorderLayout.NORTH);
 
    errorDisplay = new JLabel();
    errorDisplay.setName("error");
    errorDisplay.setFont(new Font("Dialog", Font.BOLD, 12));
 
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(mainPanel, BorderLayout.CENTER);
    getContentPane().add(errorDisplay, BorderLayout.SOUTH);
 
    pack();
    resetState();
}
 
Example 2
/**
 * This method initializes jContentPane
 * 
 * @return javax.swing.JPanel
 */
private javax.swing.JPanel getJContentPane() {
	if (jContentPane == null) {
		resultDir_label = new JLabel();
		jContentPane = new javax.swing.JPanel();
		jContentPane.setLayout(new BorderLayout());
		resultDir_label.setText("Result directory:");
		resultDir_label.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
		resultDir_label.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		resultDir_label.setName("jLabel1");
		resultDir_label.setPreferredSize(new java.awt.Dimension(129, 16));
		jContentPane.add(getJPanel4(), java.awt.BorderLayout.SOUTH);
		jContentPane.add(getJPanel(), java.awt.BorderLayout.NORTH);
		jContentPane.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
	}
	return jContentPane;
}
 
Example 3
Source Project: netbeans   File: ToolbarRow.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds a fake component and appropriate constraints that will be used to
 * visualize toolbar drop feedback.
 */
private void addDropConstraints() {
    dropConstraints = new ToolbarConstraints(FAKE_NAME, ToolbarConstraints.Align.left, false, true);
    dropReplacement = new JLabel();
    dropReplacement.setName(dropConstraints.getName());
    add( dropReplacement );
    constraints.add( dropConstraints );
}
 
Example 4
Source Project: atdl4j   File: SwingLabelWidget.java    License: MIT License 5 votes vote down vote up
private List<Component> createBrickComponents() {
  List<Component> components = new ArrayList<Component>();
  
  // label
  label = new JLabel();
  label.setName(getName()+"/label");

  if ( control.getLabel() != null )
  {
      label.setText( control.getLabel() );
  }
  else if ( ControlHelper.getInitValue(control, getAtdl4jOptions()) != null )
  {
      label.setText( (String) ControlHelper.getInitValue( control, getAtdl4jOptions() ));
  }
  else
  {
      label.setText( "" );
  }
  
  // tooltip
  if (getTooltip() != null) label.setToolTipText(getTooltip());

  components.add(label);
  
  return components;
}
 
Example 5
Source Project: iBioSim   File: PropertyField.java    License: Apache License 2.0 5 votes vote down vote up
private void init(String nameString, String valueString, String stateString) {
		name = new JLabel(nameString);
		name.setName(nameString);
		name.setText(nameString);
		this.add(name);
		if (!(valueString == null) && !(stateString == null)) {
			name.setText(CompatibilityFixer.getGuiName(nameString) + " (" + nameString + ") ");
//			idLabel = new JLabel("ID");
//			idLabel.setEnabled(false);
//			this.add(idLabel);
//			idField = new JTextField(CompatibilityFixer.getSBMLName(nameString));
//			idField.setEditable(false);
//			this.add(idField);
		}
		field = new JTextField(20);
		field.setText(valueString);
		if (stateString != null) {
			box = new JComboBox(new DefaultComboBoxModel(states));
			box.addActionListener(this);
			this.add(box);
			if (stateString.equals(states[0])) {
				setDefault();
			} else {
				setCustom();
			}
		}
		field.addActionListener(this);
		this.add(field);
	}
 
Example 6
/**
 * Creates a slightly complex child/parent swing component tree with a component at the 'bottom'
 * of that tree having the name supplied by parameter.
 */
private static SwingComponentWrapper withChildComponentName(final String childName) {
  final JLabel label = new JLabel("text");
  label.setName(childName);

  final JPanel innerPanel = new JPanel();
  innerPanel.add(new JLabel("other"));
  innerPanel.add(label);

  final JPanel panel = new JPanel();
  panel.add(innerPanel);
  panel.add(new JButton("not text type"));

  return SwingComponentWrapper.of(panel);
}
 
Example 7
@Test
void addComponents() {
  final String name = "Consiliums ridetis!";
  final JLabel component = new JLabel();
  component.setName(name);

  final JFrame frame = JFrameBuilder.builder().add(component).build();

  SwingComponentWrapper.of(frame).assertHasComponentByName(name);
}
 
Example 8
Source Project: javamelody   File: ChartsPanel.java    License: Apache License 2.0 5 votes vote down vote up
final JPanel createJRobinPanel(Map<String, byte[]> jrobins) {
	final JPanel centerPanel = new JPanel(new GridLayout(-1, NB_COLS));
	centerPanel.setOpaque(false);
	for (final Map.Entry<String, byte[]> entry : jrobins.entrySet()) {
		final String jrobinName = entry.getKey();
		final byte[] imageData = entry.getValue();
		final ImageIcon icon = new ImageIcon(imageData);
		final JLabel label = new MTransferableLabel(icon);
		// ce name sera utilisé comme nom de fichier pour le drag and drop de l'image
		label.setName(getString(jrobinName));
		label.setHorizontalAlignment(SwingConstants.CENTER);
		label.setCursor(HAND_CURSOR);
		label.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				final MWaitCursor waitCursor = new MWaitCursor(centerPanel);
				try {
					showZoomedChart(jrobinName);
				} catch (final IOException ex) {
					showException(ex);
				} finally {
					waitCursor.restore();
				}
			}
		});
		centerPanel.add(label);
	}

	final JPanel graphicsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
	graphicsPanel.setOpaque(false);
	graphicsPanel.add(centerPanel);
	return graphicsPanel;
}
 
Example 9
Source Project: atdl4j   File: SwingTextFieldWidget.java    License: MIT License 5 votes vote down vote up
@Override
public List< ? extends Component> createBrickComponents() {
  
  List<Component> components = new ArrayList<Component>();
  
// tooltip
     String tooltip = control.getTooltip();
     
     // label        
     if ( control.getLabel() != null ) {
         label = new JLabel();
         label.setName(getName()+"/label");
         label.setText(control.getLabel());
         if ( tooltip != null ) label.setToolTipText( tooltip );
     }
             
     // textField
     textField = new JFormattedTextField();
     textField.setName(getName()+"/text");
     
     // init value
     if ( ControlHelper.getInitValue( control, getAtdl4jOptions() ) != null )
         textField.setText( (String) ControlHelper.getInitValue( control, getAtdl4jOptions() ) );

     // tooltip
     if (tooltip != null) textField.setToolTipText(tooltip);

     if (label != null){
       components.add( label);
     }
     components.add( textField);

     textField.setPreferredSize(new Dimension(100, textField.getPreferredSize().height));
     
  return components;
}
 
Example 10
Source Project: atdl4j   File: SwingTextFieldWidget.java    License: MIT License 4 votes vote down vote up
public void createWidget(JPanel parent)
{
	// tooltip
	String tooltip = control.getTooltip();
	
	// label		
	if ( control.getLabel() != null ) {
		label = new JLabel();
		label.setName(getName()+"/label");
		label.setText(control.getLabel());
		if ( tooltip != null ) label.setToolTipText( tooltip );
	}
			
	// textField
	textField = new JFormattedTextField();
	textField.setName(getName()+"/text");
	
	// init value
	if ( ControlHelper.getInitValue( control, getAtdl4jOptions() ) != null )
		textField.setText( (String) ControlHelper.getInitValue( control, getAtdl4jOptions() ) );

	// tooltip
	if (tooltip != null) textField.setToolTipText(tooltip);

	if (label != null){
		wrapper = new JPanel(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 0;
    c.gridy = 0;   
    c.gridwidth = 1;
    c.weightx = 1.0;
    c.weighty = 1.0;
    c.insets = new Insets(0, 0, 0, 0);
    wrapper.add( label, c);
		c.gridx = 1;
    c.gridy = 0;
    c.insets = new Insets(0, 0, 0, 0);
    wrapper.add( textField, c);
		parent.add(wrapper);
	}
	else {
		parent.add(textField);
	}

	textField.setPreferredSize(new Dimension(100, textField.getPreferredSize().height));
	textField.revalidate();
}
 
Example 11
Source Project: atdl4j   File: SwingListBoxWidget.java    License: MIT License 4 votes vote down vote up
@Override
protected List< ? extends Component> createBrickComponents() {
  
  List<Component> components = new ArrayList<Component>();
  
  String tooltip = getTooltip();

     // label
     if ( control.getLabel() != null ) {
         label = new JLabel();
         label.setName(getName()+"/label");          
         label.setText( control.getLabel() );
         if ( tooltip != null ) label.setToolTipText( tooltip );
         components.add(label);
     }

     // listbox
     listBox =  new JList(list);
     if (control instanceof MultiSelectListT) {
         listBox.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
     } else if (control instanceof SingleSelectListT) {
         listBox.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     }
     listBox.setName(getName()+"/listbox");
     
     // listBox items
     java.util.List<ListItemT> listItems = control instanceof MultiSelectListT ? ( (MultiSelectListT) control ).getListItem()
             : ( (SingleSelectListT) control ).getListItem();
     for ( ListItemT listItem : listItems )
     {
         list.add(listItem.getUiRep() != null ? listItem.getUiRep() : "");
     }

     // tooltip
     if ( tooltip != null ) listBox.setToolTipText( tooltip );

     // init value
     String initValue = (String) ControlHelper.getInitValue( control, getAtdl4jOptions() );
     if ( initValue != null ) setValue( initValue, true );
     
     return components;
}
 
Example 12
private JDialog createAboutBox ()
{
    StringBuilder rows = new StringBuilder("pref,10dlu,pref,5dlu");

    for (int i = 0; i < (Topic.values().length); i++) {
        rows.append(",pref,3dlu");
    }

    // Layout
    final FormLayout layout = new FormLayout(
            "right:pref, 5dlu, pref, 200dlu",
            rows.toString());
    final PanelBuilder builder = new PanelBuilder(layout);
    final CellConstraints cst = new CellConstraints();

    ///builder.setDefaultDialogBorder();
    int iRow = 1;

    URI uri = UriUtil.toURI(WellKnowns.RES_URI, "splash.png");

    try {
        JPanel logoPanel = new ImagePanel(uri);
        builder.add(logoPanel, cst.xyw(1, iRow, 4));
    } catch (MalformedURLException ex) {
        logger.warn("Error on " + uri, ex);
    }

    iRow += 2;

    JLabel titleLabel = new JLabel();
    titleLabel.setName("aboutTitleLabel");
    builder.add(titleLabel, cst.xyw(1, iRow, 3));

    for (Topic topic : Topic.values()) {
        iRow += 2;

        JLabel label = new JLabel();
        label.setName(topic + "Label");
        builder.add(label, cst.xy(1, iRow));

        topic.comp.setName(topic + "TextField");
        topic.comp.setEditable(false);
        topic.comp.setBorder(null);
        topic.comp.setBackground(Color.WHITE);

        if (topic.comp instanceof JEditorPane) {
            ((JEditorPane) topic.comp).addHyperlinkListener(linkListener);
        }

        builder.add(topic.comp, cst.xy(3, iRow));
    }

    JPanel panel = builder.getPanel();
    panel.setOpaque(true);
    panel.setBackground(Color.WHITE);
    panel.setName("panel");

    JDialog dialog = new JDialog();
    dialog.setName("aboutDialog");
    dialog.add(panel, BorderLayout.CENTER);

    // Manual injection
    resource.injectComponents(dialog);
    Topic.version.comp.setText(WellKnowns.TOOL_REF + ":" + WellKnowns.TOOL_BUILD);
    Topic.classes.comp.setText(WellKnowns.CLASS_CONTAINER.toString());
    Topic.license.comp.setText("GNU Affero GPL v3");

    Topic.ocr.comp.setText(TesseractOCR.getInstance().identify());

    Topic.javaVendor.comp.setText(System.getProperty("java.vendor"));
    Topic.javaVersion.comp.setText(System.getProperty("java.version"));
    Topic.javaRuntime.comp.setText(
            System.getProperty("java.runtime.name") + " (build "
                    + System.getProperty("java.runtime.version")
                    + ")");
    Topic.javaVm.comp.setText(
            System.getProperty("java.vm.name") + " (build "
                    + System.getProperty("java.vm.version")
                    + ", "
                    + System.getProperty("java.vm.info")
                    + ")");
    Topic.os.comp.setText(
            System.getProperty("os.name") + " " + System.getProperty("os.version"));
    Topic.osArch.comp.setText(System.getProperty("os.arch"));

    return dialog;
}
 
Example 13
private static JLabel createLabel(final String postfix) {
    final String completeName = DIALOG_NAME + "." + postfix;
    final JLabel newLabel = new JLabel(completeName);
    newLabel.setName(completeName);
    return newLabel;
}
 
Example 14
private static JLabel createLabel(final String name) {
    final JLabel newLabel = new JLabel(name);
    newLabel.setName(name);
    return newLabel;
}
 
Example 15
private JLabel createLabel(final String name) {
    final JLabel newLabel = new JLabel(name);
    newLabel.setName(name);
    return newLabel;
}
 
Example 16
private static JLabel createLabel(final String name) {
    final JLabel newLabel = new JLabel(name);
    newLabel.setName(name);
    return newLabel;
}
 
Example 17
Source Project: atdl4j   File: SwingDropDownListWidget.java    License: MIT License 4 votes vote down vote up
@Override
protected List< ? extends Component> createBrickComponents() {
  ArrayList<Component> components = new ArrayList<Component>();
  
  String tooltip = getTooltip();
     
     // label
     if ( control.getLabel() != null ) {
         label = new JLabel();
         label.setName(getName()+"/label");
         label.setText( control.getLabel());
         if ( tooltip != null ) label.setToolTipText( tooltip );
     }
     
     // dropDownList
     dropDownList = new JComboBox();
     dropDownList.setName(getName()+"/dropdownlist");
     
     // set editable
     dropDownList.setEditable(control instanceof EditableDropDownListT);
     
     // dropDownList items
     List<ListItemT> listItems = ( control instanceof EditableDropDownListT ) ? ( (EditableDropDownListT) control ).getListItem()
             : ( (DropDownListT) control ).getListItem();
     // TODO: throw error if there are no list items
     for ( ListItemT listItem : listItems )
         dropDownList.addItem(listItem.getUiRep() != null ? listItem.getUiRep() : "");

     // tooltip
     if ( tooltip != null ) dropDownList.setToolTipText( tooltip );

     // default initializer
     dropDownList.setSelectedIndex(0);

     // select initValue if available
     String initValue = (String) ControlHelper.getInitValue( control, getAtdl4jOptions() );
     if ( initValue != null )
         setValue( initValue, true );
     
     
     if (label != null){
       components.add(label);
     }
     components.add( dropDownList);
  
  return components;
}
 
Example 18
Source Project: atdl4j   File: SwingCheckBoxListWidget.java    License: MIT License 4 votes vote down vote up
@Override
public List< ? extends Component> createBrickComponents() {
  
  List<Component> components = new ArrayList<Component>();
  // wrapper
  JPanel wrapper = new JPanel();
  
  // tooltip
  String tooltip = control.getTooltip();
  
  // label
  if (control.getLabel() != null) {
    label = new JLabel();
    label.setName(getName() + "/label");
    label.setText(control.getLabel());
    if (tooltip != null)
      label.setToolTipText(tooltip);
    components.add(label);
  }
  
  if (((CheckBoxListT) control).getOrientation() != null
      && PanelOrientationT.VERTICAL.equals(((CheckBoxListT) control)
          .getOrientation())) {
    // TODO: NOT IMPLEMENTED
  }
  else {
    // TODO: NOT IMPLEMENTED
  }
  
  // checkBoxes
  List<ListItemT> listItems = ((CheckBoxListT) control).getListItem();
  for (ListItemT listItem : listItems) {
  
    JCheckBox checkBox = new JCheckBox();
    checkBox.setName(getName() + "/button/" + listItem.getEnumID());
  
    if (listItem.getUiRep() != null)
      checkBox.setText(listItem.getUiRep());
  
    if (parameter != null) {
      for (EnumPairT enumPair : parameter.getEnumPair()) {
        if (enumPair.getEnumID() == listItem.getEnumID()) {
  
          // set tooltip
          if (enumPair.getDescription() != null)
            checkBox.setToolTipText(enumPair.getDescription());
          else if (tooltip != null)
            checkBox.setToolTipText(tooltip);
          break;
        }
      }
    }
    else {
      if (tooltip != null)
        checkBox.setToolTipText(tooltip);
    }
    multiCheckBox.add(checkBox);
    components.add(checkBox);
  }
  
  // set initValue
  if (((CheckBoxListT) control).getInitValue() != null)
    setValue(((CheckBoxListT) control).getInitValue(), true);
  
  return components;
}
 
Example 19
Source Project: atdl4j   File: SwingJideClockWidget.java    License: MIT License 4 votes vote down vote up
@Override
protected List< ? extends Component> createBrickComponents() {
  
  List<Component> components = new ArrayList<Component>();
  
  // tooltip
     String tooltip = control.getTooltip();      
     
     if ( parameter instanceof UTCTimestampT || parameter instanceof TZTimestampT )
     {
             if (getAtdl4jOptions()==null||getAtdl4jOptions().isShowDateInputOnTimestampClockControl())
             {
                 showMonthYear = true;
                 showDay = true;
             } else {
                 showMonthYear = false;
                 showDay = false;
                 useNowAsDate = true;
             }
         showTime = true;
     }
     else if ( parameter instanceof UTCDateOnlyT || parameter instanceof LocalMktDateT )
     {
         showMonthYear = true;
         showDay = true;
         showTime = false;
     }
     else if ( parameter instanceof MonthYearT )
     {
         showMonthYear = true;
         showDay = false;
         showTime = false;
     }
     else if ( parameter == null || parameter instanceof UTCTimeOnlyT || parameter instanceof TZTimeOnlyT )
     {
         showMonthYear = false;
         showDay = false;
         showTime = true;
     }
     
     if ( getAtdl4jOptions() != null && 
         getAtdl4jOptions().isShowEnabledCheckboxOnOptionalClockControl() && 
         parameter != null && 
         UseT.OPTIONAL.equals( parameter.getUse() ) )
     {
         hasLabelOrCheckbox = true;
         enabledButton = new JCheckBox();
         enabledButton.setName(getName()+"/enablebutton");
         if (control.getLabel() != null) {
             enabledButton.setText(control.getLabel());
         }
         enabledButton.setToolTipText("Click to enable optional parameter");
         enabledButton.setSelected(false);
         enabledButton.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
               updateFromView();                  
             }
         });
         components.add(enabledButton);
     }       
     else if (control.getLabel() != null)
     {
         // add label
         hasLabelOrCheckbox = true;
         label = new JLabel();
         label.setName(getName()+"/label");
         label.setText(control.getLabel());
         if (tooltip != null) label.setToolTipText(tooltip);
         components.add(label);
     }
     
     // date clock
     if (showMonthYear) {
         dateClock = new DateSpinner(showDay ? "dd.MM.yyyy" : "MM.yyyy");
         dateClock.setName(getName()+"/dateclock");
         if (tooltip != null) dateClock.setToolTipText(tooltip);
         components.add(dateClock);
     }
     // time clock
     if (showTime) {
         timeClock = new DateSpinner(show24HourClock ? "HH:mm:ss" : "hh:mm:ss");
         timeClock.setName(getName()+"/timeclock");
         if (tooltip != null) timeClock.setToolTipText(tooltip);
         components.add(timeClock);
     }

     // init value, if applicable
     setAndRenderInitValue( (XMLGregorianCalendar ) ControlHelper.getInitValue( control, getAtdl4jOptions() ), ((ClockT) control).getInitValueMode() );
     
     updateFromModel();
     return components;
}
 
Example 20
Source Project: atdl4j   File: SwingRadioButtonListWidget.java    License: MIT License 4 votes vote down vote up
@Override
protected List< ? extends Component> createBrickComponents() {
  List<Component> components = new ArrayList<Component>();
  
  JPanel wrapper = new JPanel();
     String tooltip = getTooltip();
                 
     // label
     if ( control.getLabel() != null ) {
         label = new JLabel();
         label.setName(getName()+"/label");
         label.setText( control.getLabel() );
         if ( tooltip != null ) label.setToolTipText( tooltip );
         components.add(label);
     }   
     
     /*
      //TODO: implement horiz/vert orientation for Swing
     if ( ((RadioButtonListT) control).getOrientation() != null &&
          PanelOrientationT.VERTICAL.equals( ((RadioButtonListT) control).getOrientation() ) )
     {
         c.setLayout( new GridLayout( 1, false ) );
     } else {
         RowLayout rl = new RowLayout();
         rl.wrap = false;
         c.setLayout( rl );
     }
      */
     
     // radioButton
     for ( ListItemT listItem : ( (RadioButtonListT) control ).getListItem() )
     {
         JRadioButton radioElement = new JRadioButton();
         radioElement.setName(getName()+"/button/"+listItem.getEnumID());
         radioElement.setText( listItem.getUiRep() );
         if ( parameter != null )
         {
             for ( EnumPairT enumPair : parameter.getEnumPair() )
             {
                 if ( enumPair.getEnumID() == listItem.getEnumID() )
                 {
                     radioElement.setToolTipText( enumPair.getDescription() );
                     break;
                 }
             }
         }
         else
         {
             radioElement.setToolTipText( tooltip );
         }
         group.add( radioElement );
         buttons.add( radioElement );
         wrapper.add( radioElement );
     }

     // set initValue (Note that this has to be the enumID, not the
     // wireValue)
     // set initValue
     if ( ControlHelper.getInitValue( control, getAtdl4jOptions() ) != null )
         setValue( (String) ControlHelper.getInitValue( control, getAtdl4jOptions() ), true );
     
     components.add(wrapper);
     return components;
}