本文整理匯總了Java中java.awt.Label.CENTER屬性的典型用法代碼示例。如果您正苦於以下問題:Java Label.CENTER屬性的具體用法?Java Label.CENTER怎麽用?Java Label.CENTER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類java.awt.Label
的用法示例。
在下文中一共展示了Label.CENTER屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: drawTextInBounds
/**
* Draws a text into a boundary. The text is clipped on the right border of the bounds.
*
* @param g The graphics context in which to draw
* @param text The text to draw
* @param x The x position of the boundary
* @param y The y position of the boundary
* @param width The width position of the boundary
* @param height The height position of the boundary
* @param alignment The alignment of the text: Label.LEFT or Label.CENTER
* @param textDescent Text text descent
*/
public static void drawTextInBounds (final Graphics2D g, final String text, final int x, final int y, final int width, final int height, final int alignment, final int textDescent)
{
if (text == null || text.length () == 0)
return;
final Dimension dim = getTextDims (g, text);
g.clipRect (x, y, width, height);
final int pos;
switch (alignment)
{
case Label.LEFT:
pos = x;
break;
case Label.CENTER:
default:
pos = x + (width - dim.width) / 2;
break;
}
g.drawString (text, pos, y + height - (height - dim.height) / 2 - textDescent);
g.setClip (null);
}
示例2: setAlignment
/**
* Sets the horizontal alignment of the label. This is implemented to
* set the alignment on the Swing label.
*
* @param alignment the horizontal alignment
*
* @see Label#LEFT
* @see Label#RIGHT
* @see Label#CENTER
*/
public void setAlignment(int alignment)
{
JLabel swingLabel = (JLabel) swingComponent.getJComponent();
switch (alignment)
{
case Label.RIGHT:
swingLabel.setHorizontalAlignment(JLabel.RIGHT);
break;
case Label.CENTER:
swingLabel.setHorizontalAlignment(JLabel.CENTER);
break;
case Label.LEFT:
default:
swingLabel.setHorizontalAlignment(JLabel.LEFT);
break;
}
}
示例3: ConsolePanel
/**
* Create a new panel to display the console output
*
* @param e The exception causing the console to be displayed
*/
public ConsolePanel(Exception e) {
setLayout(new BorderLayout());
setBackground(Color.black);
setForeground(Color.white);
Font consoleFont = new Font("Arial", Font.BOLD, 14);
Label slickLabel = new Label("SLICK CONSOLE", Label.CENTER);
slickLabel.setFont(consoleFont);
add(slickLabel, BorderLayout.PAGE_START);
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
textArea.setText(sw.toString());
textArea.setEditable(false);
add(textArea, BorderLayout.CENTER);
// add a border on both sides of the console
add(new Panel(), BorderLayout.LINE_START);
add(new Panel(), BorderLayout.LINE_END);
Panel bottomPanel = new Panel();
bottomPanel.setLayout(new GridLayout(0, 1));
Label infoLabel1 = new Label("An error occured while running the applet.", Label.CENTER);
Label infoLabel2 = new Label("Plese contact support to resolve this issue.", Label.CENTER);
infoLabel1.setFont(consoleFont);
infoLabel2.setFont(consoleFont);
bottomPanel.add(infoLabel1);
bottomPanel.add(infoLabel2);
add(bottomPanel, BorderLayout.PAGE_END);
}
示例4: convertAlignment
/**
* Converts {@code Label} alignment constant to the {@code JLabel} constant.
* If wrong Label alignment provided returns default alignment.
*
* @param alignment {@code Label} constant.
*
* @return {@code JLabel} constant.
*/
private static int convertAlignment(final int alignment) {
switch (alignment) {
case Label.CENTER:
return SwingConstants.CENTER;
case Label.RIGHT:
return SwingConstants.RIGHT;
default:
return SwingConstants.LEFT;
}
}
示例5: getGtkAlignment
float getGtkAlignment (int alignment)
{
switch (alignment)
{
case Label.LEFT:
return 0.0f;
case Label.CENTER:
return 0.5f;
case Label.RIGHT:
return 1.0f;
}
return 0.0f;
}