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

The following examples show how to use javax.swing.JLabel#setVerticalAlignment() . 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 File: ButtonDialog.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
private JPanel makeInfoPanel(String message, Icon icon) {
	JLabel infoIcon = new JLabel(icon);
	infoIcon.setVerticalAlignment(SwingConstants.TOP);
	JPanel infoPanel = new JPanel(new BorderLayout(20, 0));
	infoPanel.setBorder(BorderFactory.createEmptyBorder(12, 16, 16, 4));
	infoPanel.add(infoIcon, BorderLayout.WEST);
	int width;
	if (centerComponent != null) {
		width = (int) centerComponent.getPreferredSize().getWidth() - 88; // icon plus padding
		if (width < 420) {
			width = 420;
		}
	} else {
		width = 420;
	}

	infoTextLabel = new FixedWidthEditorPane(width, message);
	// set the background as for infoPanel such that infoTextLabel looks like a JLabel
	infoTextLabel.setBackground(infoPanel.getBackground());

	infoPanel.add(infoTextLabel, BorderLayout.CENTER);

	return infoPanel;
}
 
Example 2
Source File: DeprecationWarning.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates a deprecation panel for the given i18n key
 *
 * @param i18nKey
 * 		the {i18nKey} part of gui.label.deprecation.warning.{i18nKey}.label
 */
public DeprecationWarning(String i18nKey) {
	super(new BorderLayout());
	JPanel warning = new JPanel(new GridBagLayout());
	JLabel infoIcon = new JLabel(WARNING_ICON);
	infoIcon.setVerticalAlignment(SwingConstants.CENTER);
	GridBagConstraints gbc = new GridBagConstraints();
	warning.setBackground(Colors.WARNING_COLOR);
	gbc.insets = new Insets(5, 5, 5, 5);
	gbc.fill = GridBagConstraints.BOTH;
	warning.add(infoIcon, gbc);
	gbc.weightx = gbc.weighty = 1;
	String fullKey = String.join(ConnectionI18N.KEY_DELIMITER, DEPRECATION_PREFIX, i18nKey, ConnectionI18N.LABEL_SUFFIX);
	warning.add(createMultiLineLabel(I18N.getGUILabel(fullKey)), gbc);
	add(warning, BorderLayout.NORTH);
}
 
Example 3
Source File: InsertRecordDialog.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void refreshSQL() {
    try {
        String sqlText = "";
        if (jSplitPane1.getBottomComponent() != null) {
            SQLStatementGenerator stmtBldr = dataView.getSQLStatementGenerator();
            for (int i = 0; i < insertDataModel.getRowCount(); i++) {
                String sql = stmtBldr.generateRawInsertStatement(insertTable, getInsertValues(i));
                sqlText = sqlText + sql + "\n";
            }
            jEditorPane1.setEditorKit(CloneableEditorSupport.getEditorKit("text/x-sql")); // NOI18N
            jEditorPane1.setText(sqlText);
            jScrollPane2.setViewportView(jEditorPane1);
        }
    } catch (DBException ex) {
        JLabel errorLabel = new JLabel(
                "<html><body><font color=\"#FF0000\">" //NOI18N
                + ex.getMessage().replaceAll("\\n", "<br>") //NOI18N
                + "</font></body></html>"); //NOI18N
        errorLabel.setBorder(new EmptyBorder(5, 5, 5, 5));
        errorLabel.setVerticalAlignment(SwingConstants.TOP);
        jScrollPane2.setViewportView(errorLabel);
        jScrollPane2.revalidate();
        jScrollPane2.repaint();
    }
}
 
Example 4
Source File: NoWebServicesPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates a new instance of NoWebServiceClientsPanel */
public NoWebServicesPanel(String text) {
    setLayout(new GridBagLayout());

    label = new JLabel(text);
    label.setVerticalAlignment(SwingConstants.CENTER);
    label.setHorizontalAlignment(SwingConstants.CENTER);
    GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;

    add(label, gridBagConstraints);
}
 
Example 5
Source File: NoWebServicesPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates a new instance of NoWebServiceClientsPanel */
public NoWebServicesPanel(String text) {
    setLayout(new GridBagLayout());

    label = new JLabel(text);
    label.setVerticalAlignment(SwingConstants.CENTER);
    label.setHorizontalAlignment(SwingConstants.CENTER);
    GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;

    add(label, gridBagConstraints);
}
 
Example 6
Source File: JComponentBuilders.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void setupInstance(JLabel instance) {
    super.setupInstance(instance);
    
    instance.setText(text);
    
    if (defaultIcon != null) instance.setIcon(defaultIcon.createInstance());
    
    instance.setVerticalAlignment(verticalAlignment);
    instance.setHorizontalAlignment(horizontalAlignment);
    instance.setVerticalTextPosition(verticalTextPosition);
    instance.setHorizontalTextPosition(horizontalTextPosition);
    instance.setIconTextGap(iconTextGap);
}
 
Example 7
Source File: ThumbNailBuilder.java    From nordpos with GNU General Public License v3.0 5 votes vote down vote up
public Image getThumbNailText(Image img, String text) {

        img = getThumbNail(img);

        BufferedImage imgtext = new BufferedImage(img.getWidth(null), img.getHeight(null),  BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = imgtext.createGraphics();

        // The text
        JLabel label = new JLabel();
        label.setOpaque(false);
        label.setFont(label.getFont().deriveFont((float)m_font_size));
        //label.setText(text);
        label.setText("<html>" + text + "</html>");
        label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        label.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        Dimension d = label.getPreferredSize();
        //label.setBounds(0, 0, imgtext.getWidth(), d.height);
        label.setBounds(0, 0, imgtext.getWidth(), imgtext.getHeight());

        // 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);
        g2d.translate(0, imgtext.getHeight() - label.getHeight());
        g2d.setPaint(gpaint);
        g2d.fillRect(0 , 0, imgtext.getWidth(), label.getHeight());
        label.paint(g2d);

        g2d.dispose();

        return imgtext;
    }
 
Example 8
Source File: CSSStylesSelectionPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the panel used to display messages.
 */
private void initMessagePanel() {
    messageLabel = new JLabel();
    messageLabel.setHorizontalAlignment(SwingConstants.CENTER);
    messageLabel.setVerticalAlignment(SwingConstants.CENTER);
    messageLabel.setEnabled(false);
    messageLabel.setBackground(new BeanTreeView().getViewport().getView().getBackground());
    messageLabel.setOpaque(true);

    messagePanel = new JPanel();
    messagePanel.setLayout(new BorderLayout());
    messagePanel.add(messageLabel, BorderLayout.CENTER);
}
 
Example 9
Source File: GUISettings.java    From mvisc with GNU General Public License v3.0 5 votes vote down vote up
public static JLabel getDefaultLabel(String title, int width, int height, int align, int valign)
{
	JLabel label = new JLabel(" " + title + " ", align);
	label.setPreferredSize(new Dimension(width, height));
	label.setVerticalAlignment(valign);
	return label;
}
 
Example 10
Source File: AppPanel.java    From java-photoslibrary with Apache License 2.0 5 votes vote down vote up
private JLabel getTitleLabel(String title) {
  JLabel label =
      new JLabel(
          String.format(
              "<html><div style=\"color: %s\">%s</div></html>",
              TITLE_COLOR,
              UIHelper.getFormattedText(
                  title, TITLE_FONT_SIZE, TITLE_FONT_WEIGHT, TITLE_LINE_MARGIN)));
  label.setVerticalAlignment(SwingConstants.CENTER);
  return label;
}
 
Example 11
Source File: AppPanel.java    From java-photoslibrary with Apache License 2.0 5 votes vote down vote up
private JLabel getBackLabel(Consumer<AbstractCustomView> onBackClicked) {
  JLabel backLabel = new JLabel("", getBackIcon(), JLabel.CENTER);
  final AppPanel self = this;
  backLabel.addMouseListener(
      new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
          AbstractCustomView customView = (AbstractCustomView) self.getRootPane().getParent();
          onBackClicked.accept(customView);
        }
      });
  backLabel.setVerticalAlignment(SwingConstants.CENTER);
  return backLabel;
}
 
Example 12
Source File: JColorTable.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
public MyComboBox() {

			jPanel = new JPanel();

			GroupLayout layout = new GroupLayout(jPanel);
			jPanel.setLayout(layout);
			layout.setAutoCreateGaps(false);
			layout.setAutoCreateContainerGaps(false);

			jDefault = new JNullableLabel();
			jDefault.setHorizontalAlignment(JLabel.CENTER);
			jDefault.setVerticalAlignment(JLabel.CENTER);
			jDefault.setOpaque(true);

			jPickerIcon = new JLabel(Images.SETTINGS_COLOR_PICKER.getIcon());
			jPickerIcon.setHorizontalTextPosition(JLabel.CENTER);
			jPickerIcon.setHorizontalAlignment(JLabel.CENTER);
			jPickerIcon.setVerticalAlignment(JLabel.CENTER);
			jPickerIcon.setOpaque(true);

			layout.setHorizontalGroup(
			layout.createSequentialGroup()
					.addComponent(jDefault, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, Integer.MAX_VALUE)
					.addComponent(jPickerIcon, 16, 16, 16)
			);
			layout.setVerticalGroup(
				layout.createParallelGroup(GroupLayout.Alignment.LEADING)
					.addComponent(jDefault, 0, 0, Integer.MAX_VALUE)
					.addComponent(jPickerIcon, 0, 0, Integer.MAX_VALUE)
			);
		}
 
Example 13
Source File: VerifierSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * This is the control panel of the Verifier GUI
 */
private void createControlPanel() {
    allButton = new JRadioButton();
    org.openide.awt.Mnemonics.setLocalizedText(allButton, allString); // NOI18N
    failButton = new JRadioButton();
    org.openide.awt.Mnemonics.setLocalizedText(failButton, failString); // NOI18N
    warnButton = new JRadioButton();
    org.openide.awt.Mnemonics.setLocalizedText(warnButton, warnString); // NOI18N
    controlPanel = new JPanel();
    
    // 508 for this panel
    controlPanel.getAccessibleContext().setAccessibleName(panelName);
    controlPanel.getAccessibleContext().setAccessibleDescription(panelDesc);
    allButton.getAccessibleContext().setAccessibleName(radioButtonName);
    allButton.getAccessibleContext().setAccessibleDescription(radioButtonDesc);
    failButton.getAccessibleContext().setAccessibleName(radioButtonName);
    failButton.getAccessibleContext().setAccessibleDescription(radioButtonDesc);
    warnButton.getAccessibleContext().setAccessibleName(radioButtonName);
    warnButton.getAccessibleContext().setAccessibleDescription(radioButtonDesc);
    
    controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS));
    
    // set-up the radio buttons.
    allButton.setActionCommand(allString);
    allButton.setSelected(true);
    failButton.setActionCommand(failString);
    warnButton.setActionCommand(warnString);
    
    // Group the radio buttons.
    ButtonGroup group = new ButtonGroup();
    group.add(allButton);
    group.add(failButton);
    group.add(warnButton);
    
    // Put the radio buttons in a column in a panel
    JPanel radioPanel = new JPanel();
    // 508 for this panel
    radioPanel.getAccessibleContext().setAccessibleName(panelName);
    radioPanel.getAccessibleContext().setAccessibleDescription(panelDesc);
    radioPanel.setLayout(new BoxLayout(radioPanel, BoxLayout.X_AXIS));
    JLabel d = new JLabel(
            NbBundle.getMessage(VerifierSupport.class,"DisplayLabel")); // NOI18N
    d.setVerticalAlignment(SwingConstants.BOTTOM);
    // 508 compliance for the JLabel
    d.getAccessibleContext().setAccessibleName(
            NbBundle.getMessage(VerifierSupport.class,"Label"));    // NOI18N
    d.getAccessibleContext().setAccessibleDescription(
            NbBundle.getMessage(VerifierSupport.class,"This_is_a_label"));  // NOI18N
    radioPanel.add(d);
    radioPanel.add(allButton);
    radioPanel.add(failButton);
    radioPanel.add(warnButton);
    
    // Add the controls to the Panel
    controlPanel.add(radioPanel);
    
    // Register a listener for the report level radio buttons.
    myListener = new RadioListener();
    allButton.addActionListener(myListener);
    failButton.addActionListener(myListener);
    warnButton.addActionListener(myListener);
}
 
Example 14
Source File: ConnectToPhotosView.java    From java-photoslibrary with Apache License 2.0 4 votes vote down vote up
private JLabel getIntroLabel(String introduction) {
  JLabel introLabel = new JLabel(introduction);
  introLabel.setVerticalAlignment(SwingConstants.TOP);
  introLabel.setHorizontalAlignment(SwingConstants.LEFT);
  return introLabel;
}
 
Example 15
Source File: GraphTopComponent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void setPaneText(@NonNull final String text)  {
    final JLabel lbl = new JLabel(text);
    lbl.setHorizontalAlignment(JLabel.CENTER);
    lbl.setVerticalAlignment(JLabel.CENTER);
    pane.setViewportView(lbl);
}
 
Example 16
Source File: JFontChooser.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
private void init(Font font) {
    setLayout(new GridBagLayout());

    Insets ins = new Insets(2, 2, 2, 2);

    fontList = new JList(FONTS);
    fontList.setVisibleRowCount(10);
    fontList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    add(new JScrollPane(fontList), new GridBagConstraints(0, 0, 1, 1, 2, 2,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            ins, 0, 0));

    sizeList = new JList(SIZES);
    ((JLabel)sizeList.getCellRenderer()).setHorizontalAlignment(JLabel.RIGHT);
    sizeList.setVisibleRowCount(10);
    sizeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    add(new JScrollPane(sizeList), new GridBagConstraints(1, 0, 1, 1, 1, 2,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            ins, 0, 0));

    boldCheckBox = new JCheckBox("Bold");
    add(boldCheckBox, new GridBagConstraints(0, 1, 2, 1, 1, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE,
            ins, 0, 0));

    italicCheckBox = new JCheckBox("Italic");
    add(italicCheckBox, new GridBagConstraints(0, 2, 2, 1, 1, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE,
            ins, 0, 0));

    previewLabel = new JLabel("");
    previewLabel.setHorizontalAlignment(JLabel.CENTER);
    previewLabel.setVerticalAlignment(JLabel.CENTER);
    add(new JScrollPane(previewLabel), new GridBagConstraints(0, 3, 2, 1, 1, 1,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            ins, 0, 0));

    setFont(font == null ? previewLabel.getFont() : font);

    fontList.addListSelectionListener(selectionUpdater);
    sizeList.addListSelectionListener(selectionUpdater);
    boldCheckBox.addChangeListener(selectionUpdater);
    italicCheckBox.addChangeListener(selectionUpdater);
}
 
Example 17
Source File: EquipmentEditor.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Creates a new {@link Equipment} editor.
 *
 * @param equipment The {@link Equipment} to edit.
 * @param carried   {@code true} for the carried equipment, {@code false} for the other
 *                  equipment.
 */
public EquipmentEditor(Equipment equipment, boolean carried) {
    super(equipment);
    mCarried = carried;

    JPanel content = new JPanel(new ColumnLayout(2));
    JPanel fields  = new JPanel(new ColumnLayout(2));
    JLabel icon    = new JLabel(equipment.getIcon(true));

    mDescriptionField = createCorrectableField(fields, I18n.Text("Name"), equipment.getDescription(), I18n.Text("The name/description of the equipment, without any notes"));
    createSecondLineFields(fields);
    createValueAndWeightFields(fields);
    mNotesField = createField(fields, fields, I18n.Text("Notes"), equipment.getNotes(), I18n.Text("Any notes that you would like to show up in the list along with this equipment"), 0);
    mCategoriesField = createField(fields, fields, I18n.Text("Categories"), equipment.getCategoriesAsString(), I18n.Text("The category or categories the equipment belongs to (separate multiple categories with a comma)"), 0);

    boolean forCharacterOrTemplate = equipment.getCharacter() != null || equipment.getTemplate() != null;
    JPanel  wrapper                = new JPanel(new ColumnLayout(forCharacterOrTemplate ? 5 : 3));
    if (forCharacterOrTemplate) {
        mUsesField = createIntegerNumberField(fields, wrapper, I18n.Text("Uses"), mRow.getUses(), I18n.Text("The number of uses remaining for this equipment"), 5);
        mMaxUsesField = createIntegerNumberField(wrapper, wrapper, I18n.Text("Max Uses"), mRow.getMaxUses(), I18n.Text("The maximum number of uses for this equipment"), 5);
    } else {
        mMaxUsesField = createIntegerNumberField(fields, wrapper, I18n.Text("Max Uses"), mRow.getMaxUses(), I18n.Text("The maximum number of uses for this equipment"), 5);
    }
    mReferenceField = createField(wrapper, wrapper, I18n.Text("Page Reference"), mRow.getReference(), I18n.Text("A reference to the book and page this equipment appears on (e.g. B22 would refer to \"Basic Set\", page 22)"), 6);
    fields.add(wrapper);

    icon.setVerticalAlignment(SwingConstants.TOP);
    icon.setAlignmentY(-1.0f);
    content.add(icon);
    content.add(fields);
    add(content);

    mTabPanel = new JTabbedPane();
    mModifiers = EquipmentModifierListEditor.createEditor(mRow);
    mModifiers.addActionListener(this);
    mPrereqs = new PrereqsPanel(mRow, mRow.getPrereqs());
    mFeatures = new FeaturesPanel(mRow, mRow.getFeatures());
    mMeleeWeapons = MeleeWeaponEditor.createEditor(mRow);
    mRangedWeapons = RangedWeaponEditor.createEditor(mRow);
    mTabPanel.addTab(mMeleeWeapons.getName(), mMeleeWeapons);
    mTabPanel.addTab(mRangedWeapons.getName(), mRangedWeapons);
    Component panel = embedEditor(mPrereqs);
    mTabPanel.addTab(panel.getName(), panel);
    panel = embedEditor(mFeatures);
    mTabPanel.addTab(panel.getName(), panel);
    mTabPanel.addTab(mModifiers.getName(), mModifiers);
    if (!mIsEditable) {
        UIUtilities.disableControls(mMeleeWeapons);
        UIUtilities.disableControls(mRangedWeapons);
        UIUtilities.disableControls(mModifiers);
    }
    UIUtilities.selectTab(mTabPanel, getLastTabName());
    add(mTabPanel);
}
 
Example 18
Source File: VideoItemEditor.java    From xdm with GNU General Public License v2.0 4 votes vote down vote up
public VideoItemEditor(MediaImageSource imgSource) {
	component = new JPanel(new BorderLayout(getScaledInt(5), getScaledInt(5)));
	component.setBorder(new EmptyBorder(0, getScaledInt(5), getScaledInt(5), getScaledInt(5)));
	panel = new JPanel(new BorderLayout());
	lbl = new JLabel();
	lbl.setVerticalAlignment(JLabel.CENTER);
	lbl.setVerticalTextPosition(JLabel.CENTER);
	lbl.setFont(FontResource.getBigFont());
	lblIcon = new JLabel();
	lblIcon.setOpaque(true);
	lblIcon.setMinimumSize(new Dimension(getScaledInt(119), getScaledInt(92)));
	lblIcon.setMaximumSize(new Dimension(getScaledInt(119), getScaledInt(92)));
	lblIcon.setPreferredSize(new Dimension(getScaledInt(119), getScaledInt(92)));
	lblIcon.setHorizontalAlignment(JLabel.CENTER);
	ico = ImageResource.getIcon("videoplay.png",94,92);
	lblIcon.setIcon(ico);
	// lblIcon.setBorder(new EmptyBorder(12, 5, 5, 5));
	lblIcon.setVerticalAlignment(JLabel.CENTER);
	// lblIcon.setPreferredSize(new Dimension(53, 53));

	JPanel p1 = new JPanel(new BorderLayout());
	p1.setOpaque(false);
	p1.add(lblIcon);
	chk = new JCheckBox("");
	chk.setOpaque(false);
	chk.setIcon(ImageResource.getIcon("unchecked.png",16,16));
	chk.setSelectedIcon(ImageResource.getIcon("checked.png",16,16));
	p1.add(chk, BorderLayout.WEST);
	p1.setBorder(new EmptyBorder(getScaledInt(12), 0, getScaledInt(5), getScaledInt(5)));
	component.add(p1, BorderLayout.WEST);
	cmbModel = new DefaultComboBoxModel<>();
	cmb = new JComboBox<>(cmbModel);
	cmb.setPreferredSize(new Dimension(getScaledInt(200), getScaledInt(30)));
	cmb.setOpaque(false);
	cmb.setBorder(null);
	panel.add(lbl);
	panel.add(cmb, BorderLayout.SOUTH);
	panel.setOpaque(false);
	panel.setBorder(new EmptyBorder(0, 0, getScaledInt(5), getScaledInt(5)));
	component.add(panel);
	lblBorder = new JLabel();
	lblBorder.setPreferredSize(new Dimension(getScaledInt(100), 1));
	lblBorder.setMaximumSize(new Dimension(getScaledInt(100), 1));
	lblBorder.setBackground(ColorResource.getDarkerBgColor());
	component.add(lblBorder, BorderLayout.NORTH);
	component.setOpaque(false);
	this.imgSource = imgSource;
	// component.setBackground(ColorResource.getSelectionColor());
}
 
Example 19
Source File: OnlyMessageBox.java    From oim-fx with MIT License 4 votes vote down vote up
private void init(String message, OnlyMessageBox.MessageType messageType, int option) {

      iconMap = new HashMap<OnlyMessageBox.MessageType, Icon>();
      iconMap.put(OnlyMessageBox.MessageType.ERROR, new ImageIcon());
      iconMap.put(OnlyMessageBox.MessageType.INFORMATION, new ImageIcon());
      iconMap.put(OnlyMessageBox.MessageType.QUESTION, new ImageIcon());
      iconMap.put(OnlyMessageBox.MessageType.WARNING, new ImageIcon());

      JPanel buttonPane = new JPanel();
      lbMessage = new JLabel(message, iconMap.get(messageType), JLabel.LEFT);
      btnOK = new JButton("确定");
      btnCancel = new JButton("取消");
      btnYes = new JButton("是");
      btnNo = new JButton("否");
      JButton[] buttons = {btnOK, btnYes, btnNo, btnCancel};
      int[] options = {OK_OPTION, YES_OPTION, NO_OPTION, CANCEL_OPTION};
      final Dimension buttonSize = new Dimension(69, 21);
      int index = 0;
      boolean hasDefaultButton = false;

     
      lbMessage.setIconTextGap(16);
      lbMessage.setHorizontalAlignment(JLabel.LEFT);
      lbMessage.setVerticalAlignment(JLabel.TOP);
      lbMessage.setVerticalTextPosition(JLabel.TOP);
      lbMessage.setBorder(new EmptyBorder(15, 25, 15, 25));
      buttonPane.setLayout(new LineLayout(6, 0, 0, 0, 0, LineLayout.LEADING, LineLayout.LEADING, LineLayout.HORIZONTAL));
      buttonPane.setPreferredSize(new Dimension(-1, 33));
      buttonPane.setBorder(new EmptyBorder(5, 9, 0, 9));
      buttonPane.setBackground(new Color(255, 255, 255, 170));

      for (JButton button : buttons) {
          button.setActionCommand(String.valueOf(options[index]));
          button.setPreferredSize(buttonSize);
          button.setVisible((option & options[index]) != 0);
          button.addActionListener(this);
          buttonPane.add(button, LineLayout.END);
          index++;

          if (!hasDefaultButton && button.isVisible()) {
              getRootPane().setDefaultButton(button);
              hasDefaultButton = true;
          }
      }

      getContentPane().setLayout(new LineLayout(0, 1, 1, 3, 1, LineLayout.LEADING, LineLayout.LEADING, LineLayout.VERTICAL));
      getContentPane().add(lbMessage, LineLayout.MIDDLE_FILL);
      getContentPane().add(buttonPane, LineLayout.END_FILL);
  }
 
Example 20
Source File: SharedFunctions.java    From zap-extensions with Apache License 2.0 4 votes vote down vote up
public static void allignLabelTop(JLabel lbl) {
    lbl.setVerticalAlignment(JLabel.TOP);
    lbl.setVerticalTextPosition(JLabel.TOP);
    lbl.setBorder(BorderFactory.createEmptyBorder(3 /* top */, 0, 0, 0));
}