当前位置: 首页>>代码示例>>Java>>正文


Java Label.CENTER属性代码示例

本文整理汇总了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);
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:33,代码来源:AbstractGridElement.java

示例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;
    }
}
 
开发者ID:vilie,项目名称:javify,代码行数:27,代码来源:SwingLabelPeer.java

示例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);
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:37,代码来源:AppletGameContainer.java

示例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;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:LWLabelPeer.java

示例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;
}
 
开发者ID:vilie,项目名称:javify,代码行数:14,代码来源:GtkLabelPeer.java


注:本文中的java.awt.Label.CENTER属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。