Java Code Examples for javax.swing.SwingConstants#CENTER

The following examples show how to use javax.swing.SwingConstants#CENTER . 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: PlayerList.java    From ChatUI with MIT License 6 votes vote down vote up
private TableRenderer createTableRenderer(TableScrollHelper scroll) {
    return new DefaultTableRenderer() {

        private final TableViewport viewport = scroll.createViewport();

        @Override
        public TableViewport getViewport() {
            return this.viewport;
        }

        @Override
        protected int getCellAlignment(int row, int column) {
            if (column == 0) {
                return SwingConstants.RIGHT;
            }
            return SwingConstants.CENTER;
        }

    };
}
 
Example 2
Source File: NotSupportedDisplayer.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates new instance of NotSupportedDisplayer.
 * 
 * @param object type of the not supported object (any string or predefined constant).
 */
public NotSupportedDisplayer(String object) {
    JLabel notSupportedLabel = new JLabel(NbBundle.getMessage(NotSupportedDisplayer.class, "MSG_Not_supported", object), SwingConstants.CENTER);    // NOI18N
    notSupportedLabel.setEnabled(false);

    setLayout(new BorderLayout());
    setOpaque(false);
    
    add(notSupportedLabel, BorderLayout.CENTER);
}
 
Example 3
Source File: GroupListRenderer.java    From ChatUI with MIT License 5 votes vote down vote up
@Override
protected int getCellAlignment(int row, int column) {
    if (column == 1) {
        return SwingConstants.CENTER;
    }
    return super.getCellAlignment(row, column);
}
 
Example 4
Source File: PageHeader.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link PageHeader}.
 *
 * @param title   The title to use.
 * @param tooltip The tooltip to use.
 */
public PageHeader(String title, String tooltip) {
    super(title, SwingConstants.CENTER);
    setFont(UIManager.getFont(Fonts.KEY_LABEL_PRIMARY));
    setForeground(Color.white);
    setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
}
 
Example 5
Source File: StopWatch.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public StopWatch() {
      super();
      CLOCK_TIMER = new Timer(100, this);
      INNER_BOUNDS = new Rectangle(200, 200);
      init(INNER_BOUNDS.width, INNER_BOUNDS.height);
      setPointerColor(ColorDef.BLACK);
      setBackgroundColor(BackgroundColor.LIGHT_GRAY);
      horizontalAlignment = SwingConstants.CENTER;
verticalAlignment = SwingConstants.CENTER;
  }
 
Example 6
Source File: StatPanel.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
protected void initLayout() {
  final boolean hasTech = !TechAdvance.getTechAdvances(gameData, null).isEmpty();
  // do no include a grid box for tech if there is no tech
  setLayout(new GridLayout((hasTech ? 2 : 1), 1));
  final JTable statsTable = new JTable(dataModel);
  statsTable.getTableHeader().setReorderingAllowed(false);
  statsTable.getColumnModel().getColumn(0).setPreferredWidth(175);
  add(new JScrollPane(statsTable));
  // if no technologies, do not show the tech table
  if (!hasTech) {
    return;
  }
  final JTable techTable = new JTable(techModel);
  techTable.getTableHeader().setReorderingAllowed(false);
  techTable.getColumnModel().getColumn(0).setPreferredWidth(500);
  // show icons for players:
  final TableCellRenderer componentRenderer = new JComponentTableCellRenderer();
  for (int i = 1; i < techTable.getColumnCount(); i++) {
    final TableColumn column = techTable.getColumnModel().getColumn(i);
    column.setHeaderRenderer(componentRenderer);
    final String player = techTable.getColumnName(i);
    final JLabel value = new JLabel("", getIcon(player), SwingConstants.CENTER);
    value.setToolTipText(player);
    column.setHeaderValue(value);
  }
  add(new JScrollPane(techTable));
}
 
Example 7
Source File: StyleEditor.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
Style() {
  hAlign     = SwingConstants.CENTER;
  vAlign     = SwingConstants.CENTER;
  background = Color.white;
  foreground = Color.black;
  font       = new Font("Dialog", Font.PLAIN, 12);
}
 
Example 8
Source File: HTMLLabel.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void setText(String value) {
    txt = value;
    
    Font font = getFont();
    Color fgColor = getForeground();
    Color bgColor = getBackground();
    
    value = value.replaceAll("\\n\\r|\\r\\n|\\n|\\r", "<br>"); //NOI18N
    value = value.replace("<code>", "<code style=\"font-size: " + font.getSize() + "pt;\">"); //NOI18N
    
    String fgText = "rgb(" + fgColor.getRed() + "," + fgColor.getGreen() + "," + fgColor.getBlue() + ")"; //NOI18N
    String bgText = isOpaque() ? "rgb(" + bgColor.getRed() + "," + bgColor.getGreen() + "," + bgColor.getBlue() + ")" : null; //NOI18N
    
    String alignText = null;
    switch (halign) {
        case SwingConstants.CENTER:
            alignText = "center"; //NOI18N
            break;
        case SwingConstants.RIGHT:
        case SwingConstants.TRAILING:
            alignText = "right"; //NOI18N
            break;
    }
    
    String bodyFlags = "text=\"" + fgText + "\""; //NOI18N
    if (bgText != null) bodyFlags += " bgcolor=\"" + bgText + "\""; //NOI18N
    if (alignText != null) bodyFlags += " align=\"" + alignText + "\""; //NOI18N
    
    super.setText("<html><body " + bodyFlags + " style=\"font-size: " + font.getSize() //NOI18N
                  + "pt; font-family: " + font.getName() + ";\">" + value + "</body></html>"); //NOI18N
}
 
Example 9
Source File: Clock.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public Clock() {
      super();
      CLOCK_TIMER = new Timer(1000, this);
      INNER_BOUNDS = new Rectangle(200, 200);
      init(getInnerBounds().width, getInnerBounds().height);
      setPointerColor(ColorDef.BLACK);
      horizontalAlignment = SwingConstants.CENTER;
verticalAlignment = SwingConstants.CENTER;
      //CLOCK_TIMER.start();
  }
 
Example 10
Source File: ProfilerTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static boolean isLeadingAlign(Component component) {
    int alignment;
    
    if (component instanceof ProfilerRenderer) {
        alignment = ((ProfilerRenderer)component).getHorizontalAlignment();
    } else if (component instanceof JLabel) {
        alignment = ((JLabel)component).getHorizontalAlignment();
    } else {
        alignment = SwingConstants.LEADING;
    }
    
    return alignment == SwingConstants.LEADING ||
           alignment == SwingConstants.LEFT ||
           alignment == SwingConstants.CENTER;
}
 
Example 11
Source File: MessageComponent.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public MessageComponent(String message) {
    JLabel notSupportedLabel = new JLabel(message, SwingConstants.CENTER);    // NOI18N
    notSupportedLabel.setEnabled(false);

    setLayout(new BorderLayout());
    setOpaque(false);
    
    add(notSupportedLabel, BorderLayout.CENTER);
}
 
Example 12
Source File: LicenseDialog.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create a title panel
 *
 * @param boutonLicense if true, show the license button
 * @return the panel
 */
public static JComponent createHeaderPanel(final boolean boutonLicense, final Window parent) {
	if (boutonLicense) {
		final JButton license = new JButton(Resources.getLabel("license.label"), Resources.getImageIcon("route.png"));
		license.addActionListener(e -> {
			final LicenseDialog dialog = new LicenseDialog(parent);
			dialog.setVisible(true);
		});
		return license;
	} else {
		return new JLabel(Resources.getLabel("appli.title", Resources.getVersion()), Resources.getImageIcon("route.png"), SwingConstants.CENTER);
	}
}
 
Example 13
Source File: TextDrawing.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Draws the text. Embedded return characters may be present.
 *
 * @param gc              The graphics context.
 * @param bounds          The bounding rectangle to draw the text within.
 * @param text            The text to draw.
 * @param hAlign          The horizontal alignment to use. One of {@link SwingConstants#LEFT},
 *                        {@link SwingConstants#CENTER}, or {@link SwingConstants#RIGHT}.
 * @param vAlign          The vertical alignment to use. One of {@link SwingConstants#LEFT},
 *                        {@link SwingConstants#CENTER}, or {@link SwingConstants#RIGHT}.
 * @param strikeThruColor If not {@code null}, then a line of this color will be drawn through
 *                        the text.
 * @param strikeThruSize  The line width to use when drawing the strike-thru.
 * @return The bottom of the drawn text.
 */
public static final int draw(Graphics gc, Rectangle bounds, String text, int hAlign, int vAlign, Color strikeThruColor, int strikeThruSize) {
    int y = bounds.y;
    if (!text.isEmpty()) {
        List<String> list    = new ArrayList<>();
        Font         font    = gc.getFont();
        FontMetrics  fm      = gc.getFontMetrics();
        int          ascent  = fm.getAscent();
        int          descent = fm.getDescent();
        // Don't use fm.getHeight(), as the PC adds too much dead space
        int             fHeight    = ascent + descent;
        StringTokenizer tokenizer  = new StringTokenizer(text, " \n", true);
        StringBuilder   buffer     = new StringBuilder(text.length());
        int             textHeight = 0;
        int             width;
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken();
            if (token.equals(NEWLINE)) {
                text = buffer.toString();
                textHeight += fHeight;
                list.add(text);
                buffer.setLength(0);
            } else {
                width = getSimpleWidth(font, buffer + token);
                if (width > bounds.width && buffer.length() > 0) {
                    text = buffer.toString();
                    textHeight += fHeight;
                    list.add(text);
                    buffer.setLength(0);
                }
                buffer.append(token);
            }
        }
        if (buffer.length() > 0) {
            text = buffer.toString();
            textHeight += fHeight;
            list.add(text);
        }
        if (vAlign == SwingConstants.CENTER) {
            y = bounds.y + (bounds.height - textHeight) / 2;
        } else if (vAlign == SwingConstants.BOTTOM) {
            y = bounds.y + bounds.height - textHeight;
        }
        for (String piece : list) {
            width = 0;
            int x = bounds.x;
            if (hAlign == SwingConstants.CENTER) {
                width = getSimpleWidth(font, piece);
                x += (bounds.width - width) / 2;
            } else if (hAlign == SwingConstants.RIGHT) {
                width = getSimpleWidth(font, piece);
                x += bounds.width - (1 + width);
            }
            gc.drawString(piece, x, y + ascent);
            if (strikeThruColor != null) {
                Color saved = gc.getColor();
                gc.setColor(strikeThruColor);
                if (width == 0) {
                    width = getSimpleWidth(font, piece);
                }
                gc.fillRect(x, y + (ascent - strikeThruSize) / 2, x + width, strikeThruSize);
                gc.setColor(saved);
            }
            y += fHeight;
        }
    }
    return y;
}
 
Example 14
Source File: StyleEditor.java    From pdfxtk with Apache License 2.0 4 votes vote down vote up
static boolean validVerticalKey(int key) {
  return ((key == SwingConstants.TOP) || (key == SwingConstants.CENTER) || (key == SwingConstants.BOTTOM));
}
 
Example 15
Source File: ElementTreePanel.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
public ElementTreePanel(JTextComponent editor) {
    this.editor = editor;

    Document document = editor.getDocument();

    // Create the tree.
    treeModel = new ElementTreeModel(document);
    tree = new JTree(treeModel) {

        @Override
        public String convertValueToText(Object value, boolean selected,
                boolean expanded, boolean leaf,
                int row, boolean hasFocus) {
            // Should only happen for the root
            if (!(value instanceof Element)) {
                return value.toString();
            }

            Element e = (Element) value;
            AttributeSet as = e.getAttributes().copyAttributes();
            String asString;

            if (as != null) {
                StringBuilder retBuffer = new StringBuilder("[");
                Enumeration names = as.getAttributeNames();

                while (names.hasMoreElements()) {
                    Object nextName = names.nextElement();

                    if (nextName != StyleConstants.ResolveAttribute) {
                        retBuffer.append(" ");
                        retBuffer.append(nextName);
                        retBuffer.append("=");
                        retBuffer.append(as.getAttribute(nextName));
                    }
                }
                retBuffer.append(" ]");
                asString = retBuffer.toString();
            } else {
                asString = "[ ]";
            }

            if (e.isLeaf()) {
                return e.getName() + " [" + e.getStartOffset() + ", " + e.
                        getEndOffset() + "] Attributes: " + asString;
            }
            return e.getName() + " [" + e.getStartOffset() + ", " + e.
                    getEndOffset() + "] Attributes: " + asString;
        }
    };
    tree.addTreeSelectionListener(this);
    tree.setDragEnabled(true);
    // Don't show the root, it is fake.
    tree.setRootVisible(false);
    // Since the display value of every node after the insertion point
    // changes every time the text changes and we don't generate a change
    // event for all those nodes the display value can become off.
    // This can be seen as '...' instead of the complete string value.
    // This is a temporary workaround, increase the needed size by 15,
    // hoping that will be enough.
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Dimension getPreferredSize() {
            Dimension retValue = super.getPreferredSize();
            if (retValue != null) {
                retValue.width += 15;
            }
            return retValue;
        }
    });
    // become a listener on the document to update the tree.
    document.addDocumentListener(this);

    // become a PropertyChangeListener to know when the Document has
    // changed.
    editor.addPropertyChangeListener(this);

    // Become a CaretListener
    editor.addCaretListener(this);

    // configure the panel and frame containing it.
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    // Add a label above tree to describe what is being shown
    JLabel label = new JLabel("Elements that make up the current document",
            SwingConstants.CENTER);

    label.setFont(new Font("Dialog", Font.BOLD, 14));
    add(label, BorderLayout.NORTH);

    setPreferredSize(new Dimension(400, 400));
}
 
Example 16
Source File: Led.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public Led() {
      super();
      INNER_BOUNDS        = new Rectangle(16, 16);
      ledColor            = LedColor.RED_LED;
      customLedColor      = new CustomLedColor(Color.RED);
      ledImageOff         = create_LED_Image(16, 0, ledColor, LedType.ROUND);
      ledImageOn          = create_LED_Image(16, 1, ledColor, LedType.ROUND);
      currentLedImage     = ledImageOff;
      LED_BLINKING_TIMER  = new javax.swing.Timer(500, this);
      ledBlinking         = false;
      ledOn               = false;
      ledType             = LedType.ROUND;
      initialized         = false;
      COMPONENT_LISTENER  = new ComponentAdapter() {
          @Override
          public void componentResized(ComponentEvent event) {
              final int SIZE = getWidth() <= getHeight() ? getWidth() : getHeight();
              java.awt.Container parent = getParent();
              if ((parent != null) && (parent.getLayout() == null)) {
                  if (SIZE < getMinimumSize().width || SIZE < getMinimumSize().height) {
                      setSize(getMinimumSize().width, getMinimumSize().height);
                  } else {
                      setSize(SIZE, SIZE);
                  }
              } else {
                  if (SIZE < getMinimumSize().width || SIZE < getMinimumSize().height) {
                      setPreferredSize(getMinimumSize());
                  } else {
                      setPreferredSize(new java.awt.Dimension(SIZE, SIZE));
                  }
              }

              calcInnerBounds();

              init(INNER_BOUNDS.width);
              //revalidate();
              //repaint(INNER_BOUNDS);

          }
      };
      horizontalAlignment = SwingConstants.CENTER;
verticalAlignment   = SwingConstants.CENTER;
      init(INNER_BOUNDS.width);
      addComponentListener(COMPONENT_LISTENER);
  }
 
Example 17
Source File: ColorFormModel.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
public Component createEmptyContentPanel() {
    return new JLabel("<html>This tool window is used to manipulate the<br>" +
                      "<b>colouring of images</b> shown in an image view.<br>" +
                      " Right now, there is no selected image view.", SwingConstants.CENTER);
}
 
Example 18
Source File: RowEditor.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Brings up a modal detailed editor for each row in the list.
 *
 * @param owner The owning component.
 * @param list  The rows to edit.
 * @return Whether anything was modified.
 */
@SuppressWarnings("unused")
public static boolean edit(Component owner, List<? extends ListRow> list) {
    ArrayList<RowUndo> undos = new ArrayList<>();
    ListRow[]          rows  = list.toArray(new ListRow[0]);

    int length = rows.length;
    for (int i = 0; i < length; i++) {
        boolean                      hasMore = i != length - 1;
        ListRow                      row     = rows[i];
        RowEditor<? extends ListRow> editor  = row.createEditor();
        String                       title   = MessageFormat.format(I18n.Text("Edit {0}"), row.getRowType());
        JPanel                       wrapper = new JPanel(new BorderLayout());

        if (hasMore) {
            int    remaining = length - i - 1;
            String msg       = remaining == 1 ? I18n.Text("1 item remaining to be edited.") : MessageFormat.format(I18n.Text("{0} items remaining to be edited."), Integer.valueOf(remaining));
            JLabel panel     = new JLabel(msg, SwingConstants.CENTER);
            panel.setBorder(new EmptyBorder(0, 0, 10, 0));
            wrapper.add(panel, BorderLayout.NORTH);
        }
        wrapper.add(editor, BorderLayout.CENTER);

        int      type       = hasMore ? JOptionPane.YES_NO_CANCEL_OPTION : JOptionPane.YES_NO_OPTION;
        String   applyText  = I18n.Text("Apply");
        String   cancelText = I18n.Text("Cancel");
        String[] options    = hasMore ? new String[]{applyText, cancelText, I18n.Text("Cancel Remaining")} : new String[]{applyText, cancelText};
        switch (WindowUtils.showOptionDialog(owner, wrapper, title, true, type, JOptionPane.PLAIN_MESSAGE, null, options, applyText)) {
        case JOptionPane.YES_OPTION:
            RowUndo undo = new RowUndo(row);
            if (editor.applyChanges()) {
                if (undo.finish()) {
                    undos.add(undo);
                }
            }
            break;
        case JOptionPane.NO_OPTION:
            break;
        case JOptionPane.CANCEL_OPTION:
        case JOptionPane.CLOSED_OPTION:
        default:
            i = length;
            break;
        }
        editor.finished();
    }

    if (!undos.isEmpty()) {
        new MultipleRowUndo(undos);
        return true;
    }
    return false;
}
 
Example 19
Source File: BranchSubstitutionModelEditor.java    From beast-mcmc with GNU Lesser General Public License v2.1 2 votes vote down vote up
public BranchSubstitutionModelEditor(PartitionDataList dataList, int row) {
	
	this.dataList = dataList;
	this.row = row;
	
	substitutionParameterFields = new RealNumberField[PartitionData.substitutionParameterNames.length];
	window = new JDialog(owner, "Setup substitution model for partition " + (row + 1));
	optionPanel = new OptionsPanel(12, 12, SwingConstants.CENTER);
	
	substitutionCombo = new DisabledItemsComboBox();
	substitutionCombo.setOpaque(false);

	int indexOf = 0;
	for (String substitutionModel : PartitionData.substitutionModels) {

		if (PartitionData.substitutionCompatibleDataTypes[indexOf] == dataList.get(row).dataTypeIndex) {

			substitutionCombo.addItem(substitutionModel, false);

		} else {

			substitutionCombo.addItem(substitutionModel, true);

		}

		indexOf++;
	}// END: fill loop

	substitutionCombo.addItemListener(new ListenSubstitutionCombo());
	
	for (int i = 0; i < PartitionData.substitutionParameterNames.length; i++) {
		
		substitutionParameterFields[i] = new RealNumberField(0.0, Double.MAX_VALUE);
		substitutionParameterFields[i].setColumns(8);
		substitutionParameterFields[i].setValue(this.dataList.get(row).substitutionParameterValues[i]);
		
	}// END: fill loop

	setSubstitutionArguments();

	// Buttons
	JPanel buttonsHolder = new JPanel();
	buttonsHolder.setOpaque(false);
	
	cancel = new JButton("Cancel", Utils.createImageIcon(Utils.CLOSE_ICON));
	cancel.addActionListener(new ListenCancel());
	buttonsHolder.add(cancel);
	
	done = new JButton("Done", Utils.createImageIcon(Utils.CHECK_ICON));
	done.addActionListener(new ListenOk());
	buttonsHolder.add(done);
	
	// Window
	owner = Utils.getActiveFrame();
	window.setLocationRelativeTo(owner);
	window.getContentPane().setLayout(new BorderLayout());
	window.getContentPane().add(optionPanel, BorderLayout.CENTER);
	window.getContentPane().add(buttonsHolder, BorderLayout.SOUTH);
	window.pack();
	
	//return to the previously chosen index on start
	substitutionCombo.setSelectedIndex(dataList.get(row).substitutionModelIndex);
	
}
 
Example 20
Source File: Task.java    From ghidra with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the alignment of the text displayed in the modal dialog.  The default is
 * {@link SwingConstants#CENTER}.   For status updates where the initial portion of the
 * text does not change, {@link SwingConstants#LEADING} is recommended.  To change the
 * default value, simply override this method and return one of {@link SwingConstants}
 * CENTER, LEADING or TRAILING.
 *
 * @return the alignment of the text displayed
 */
public int getStatusTextAlignment() {
	return SwingConstants.CENTER;
}