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

The following examples show how to use javax.swing.JLabel#add() . 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: knife   File: ComBoxEditor.java    License: MIT License 5 votes vote down vote up
public ComBoxEditor()
{
	m_ComboBox = new JComboBox();
	m_ComboBox.addItem("选项A");
	m_ComboBox.addItem("选项B");
	m_ComboBox.addItem("选项C");
	
	m_ComboBox.setSize(100,30);
	
	m_OutLable= new JLabel();
	m_OutLable.setLayout(null);
	m_OutLable.setBounds(0, 0, 120, 40);
	m_OutLable.add(m_ComboBox);
	m_ComboBox.setLocation(50, 50);
	
	//响应下拉列表的事件
	m_ComboBox.addItemListener(new ItemListener()
	{
		@Override
		public void itemStateChanged(ItemEvent e)
		{
			System.out.println("下拉列表的选中事件");
			if(e.getStateChange() == e.SELECTED)
			{
				//获取选择的值
				m_SelStr = (String)m_ComboBox.getSelectedItem();
				//结束选择
				fireEditingStopped();
			}
		}
	});
}
 
Example 2
Source Project: SimpleERP   File: Chooser.java    License: Apache License 2.0 5 votes vote down vote up
private void initTitlePanel(){
    preYear = new JLabel("<<", JLabel.CENTER);
    preMonth = new JLabel("<", JLabel.CENTER);
    center = new JLabel("", JLabel.CENTER);
    centercontainer = new JLabel("", JLabel.CENTER);
    nextMonth = new JLabel(">", JLabel.CENTER);
    nextYear = new JLabel(">>", JLabel.CENTER);
    
    preYear.setToolTipText("Last Year");
    preMonth.setToolTipText("Last Month");
    nextMonth.setToolTipText("Next Month");
    nextYear.setToolTipText("Next Year");
    
    preYear.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 10, 0, 0));
    preMonth.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 15, 0, 0));
    nextMonth.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 0, 0, 15));
    nextYear.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 0, 0, 10));
    
    centercontainer.setLayout(new java.awt.BorderLayout());
    centercontainer.add(preMonth,java.awt.BorderLayout.WEST);
    centercontainer.add(center,java.awt.BorderLayout.CENTER);
    centercontainer.add(nextMonth,java.awt.BorderLayout.EAST);
    
    this.add(preYear,java.awt.BorderLayout.WEST);
    this.add(centercontainer,java.awt.BorderLayout.CENTER);
    this.add(nextYear,java.awt.BorderLayout.EAST);
    this.setPreferredSize(new java.awt.Dimension(210, 25));
    
    updateDate();
    
    preYear.addMouseListener(new MyMouseAdapter(preYear, Calendar.YEAR, -1));
    preMonth.addMouseListener(new MyMouseAdapter(preMonth, Calendar.MONTH, -1));
    nextMonth.addMouseListener(new MyMouseAdapter(nextMonth, Calendar.MONTH, 1));
    nextYear.addMouseListener(new MyMouseAdapter(nextYear, Calendar.YEAR, 1));
}
 
Example 3
private void categorizeUnits(
    final Iterable<UnitCategory> categoryIter, final boolean damaged, final boolean disabled) {
  for (final UnitCategory category : categoryIter) {
    final JPanel panel = new JPanel();
    // TODO Kev determine if we need to identify if the unit is hit/disabled
    final Optional<ImageIcon> unitImage =
        uiContext
            .getUnitImageFactory()
            .getIcon(
                category.getType(),
                category.getOwner(),
                damaged && category.hasDamageOrBombingUnitDamage(),
                disabled && category.getDisabled());
    final JLabel unit = unitImage.map(JLabel::new).orElseGet(JLabel::new);
    panel.add(unit);
    // Add a tooltip, with a count of 1 so that the tooltip doesn't have a number label (so it
    // won't get out of date
    // when units are killed.)
    MapUnitTooltipManager.setUnitTooltip(unit, category.getType(), category.getOwner(), 1);
    for (final UnitOwner owner : category.getDependents()) {
      unit.add(uiContext.newUnitImageLabel(owner.getType(), owner.getOwner()));
    }
    panel.add(new JLabel("x " + category.getUnits().size()));
    if (damaged) {
      this.damaged.add(panel);
    } else {
      killed.add(panel);
    }
  }
}
 
Example 4
Source Project: dummydroid   File: MainWindow.java    License: Apache License 2.0 4 votes vote down vote up
public MainWindow() {
	super("Dummy Droid");
	setDefaultCloseOperation(EXIT_ON_CLOSE);
	JMenuBar mbar = new JMenuBar();
	JMenu fileMenu = new JMenu(new FileMenuAction());
	fileMenu.add(new JMenuItem(new QuitAction()));
	mbar.add(fileMenu);
	setJMenuBar(mbar);

	FormData formData = new FormData();

	JEditorPane description = new HypertextPane("");
	description.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
	description.addHyperlinkListener(new BrowseUtil());
	JPanel formContainer = new JPanel();
	formContainer.setLayout(new CardLayout());

	NavigateAction forward = new NavigateAction(description, formContainer, NavigateAction.FORWARD,
			formData);
	NavigateAction backward = new NavigateAction(description, formContainer, NavigateAction.BACK,
			formData);

	formContainer.add(new LoadForm(forward, backward), LoadForm.class.getName());
	formContainer.add(new HardwareForm(forward, backward), HardwareForm.class.getName());
	formContainer.add(new SoftwareForm(forward, backward), SoftwareForm.class.getName());
	formContainer.add(new MiscForm(forward, backward), MiscForm.class.getName());
	formContainer.add(new NativeForm(forward, backward), NativeForm.class.getName());
	formContainer.add(new SharedlibForm(forward, backward), SharedlibForm.class.getName());
	formContainer.add(new FeaturesForm(forward, backward), FeaturesForm.class.getName());
	formContainer.add(new LocalesForm(forward, backward), LocalesForm.class.getName());
	formContainer.add(new CredentialsForm(forward,backward),CredentialsForm.class.getName());
	formContainer.add(new CheckinForm(forward, backward), CheckinForm.class.getName());

	JButton next = new JButton(forward);
	JButton previous = new JButton(backward);
	JLabel content = new JLabel("");
	JPanel buttonBar = new JPanel(new FlowLayout(FlowLayout.RIGHT));
	buttonBar.add(previous);
	buttonBar.add(next);
	content.setLayout(new BorderLayout());
	JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
			new JScrollPane(description), formContainer);
	splitPane.setResizeWeight(1);
	content.add(splitPane, BorderLayout.CENTER);
	content.add(buttonBar, BorderLayout.SOUTH);
	setContentPane(content);
	forward.toScreen();
}