Java Code Examples for java.awt.Label#CENTER

The following examples show how to use java.awt.Label#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: ComplexSurfacePlot.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws string at the specified coordinates with the specified alignment.
 *
 * @param g       graphics context to draw
 * @param x       the x coordinate
 * @param y       the y coordinate
 * @param s       the string to draw
 * @param x_align the alignment in x direction
 * @param y_align the alignment in y direction
 */
private final void outString(Graphics g, int x, int y, String s, int x_align, int y_align) {
  switch(y_align) {
     case TOP :
       y += g.getFontMetrics(g.getFont()).getAscent();
       break;
     case CENTER :
       y += g.getFontMetrics(g.getFont()).getAscent()/2;
       break;
  }
  switch(x_align) {
     case Label.LEFT :
       g.drawString(s, x, y);
       break;
     case Label.RIGHT :
       g.drawString(s, x-g.getFontMetrics(g.getFont()).stringWidth(s), y);
       break;
     case Label.CENTER :
       g.drawString(s, x-g.getFontMetrics(g.getFont()).stringWidth(s)/2, y);
       break;
  }
}
 
Example 2
Source File: SurfacePlot.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws string at the specified coordinates with the specified alignment.
 *
 * @param g       graphics context to draw
 * @param x       the x coordinate
 * @param y       the y coordinate
 * @param s       the string to draw
 * @param x_align the alignment in x direction
 * @param y_align the alignment in y direction
 */
private final void outString(Graphics g, int x, int y, String s, int x_align, int y_align) {
  if((s==null)||s.trim().equals("")) { //$NON-NLS-1$
    return;
  }
  switch(y_align) {
     case TOP :
       y += g.getFontMetrics(g.getFont()).getAscent();
       break;
     case CENTER :
       y += g.getFontMetrics(g.getFont()).getAscent()/2;
       break;
  }
  switch(x_align) {
     case Label.LEFT :
       g.drawString(s, x, y);
       break;
     case Label.RIGHT :
       g.drawString(s, x-g.getFontMetrics(g.getFont()).stringWidth(s), y);
       break;
     case Label.CENTER :
       g.drawString(s, x-g.getFontMetrics(g.getFont()).stringWidth(s)/2, y);
       break;
  }
}
 
Example 3
Source File: LWLabelPeer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 4
Source File: AppletGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source File: LWLabelPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 6
Source File: LWLabelPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 7
Source File: Sage.java    From sagetv with Apache License 2.0 5 votes vote down vote up
private static void splashAndLicense()
{
  splashWindow = new Window(masterWindow);
  splashWindow.setLayout(new BorderLayout());
  Image theImage = null;
  String splashImageName;
  if (Sage.get("ui/splash_image", null) != null)
  {
    theImage = Toolkit.getDefaultToolkit().createImage(Sage.get("ui/splash_image", null));
    ImageUtils.ensureImageIsLoaded(theImage);
  }
  else
  {
    theImage = ImageUtils.fullyLoadImage(isTrueClient() ? (is64BitJVM() ? "images/splashclient64.gif" : "images/splashclient.gif") : 
                                                          (is64BitJVM() ? "images/splash64.gif"       : "images/splash.gif"      ));
  }
  ActiveImage splashImage = new ActiveImage(theImage);
  splashWindow.add(splashImage, "Center");
  splashText = new Label(Sage.rez("Module_Init", new Object[] { "Application" }), Label.CENTER)
  {
    public void paint(Graphics g)
    {
      super.paint(g);
      g.setColor(Color.black);
      g.drawRect(0, 0, getWidth()-1, getHeight()-1);
    }
  };
  splashText.setBackground(new Color(42, 103, 190));
  splashText.setForeground(Color.white);
  splashWindow.add(splashText, "South");
  Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
  splashWindow.pack();
  Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
  splashWindow.setLocation(center.x - splashWindow.getWidth()/2, center.y - splashWindow.getHeight()/2);
  splashWindow.setVisible(true);
}
 
Example 8
Source File: LWLabelPeer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 9
Source File: LWLabelPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 10
Source File: LWLabelPeer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 11
Source File: LWLabelPeer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 12
Source File: LWLabelPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 13
Source File: LWLabelPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 14
Source File: LWLabelPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 15
Source File: LWLabelPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 16
Source File: LWLabelPeer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 17
Source File: LWLabelPeer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 18
Source File: BigDataViewerTransformationWindow.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public BigDataViewerTransformationWindow( final BigDataViewer bdv )
{
	this.t = new AffineTransform3D();
	final Frame frame = new Frame( "Current Global Transformation" );
	frame.setSize( 400, 200 );

	/* Instantiation */
	final GridBagLayout layout = new GridBagLayout();
	final GridBagConstraints c = new GridBagConstraints();

	final Label text1 = new Label( "1.00000   0.00000   0.00000   0.00000", Label.CENTER );
	final Label text2 = new Label( "0.00000   1.00000   0.00000   0.00000", Label.CENTER );
	final Label text3 = new Label( "0.00000   0.00000   1.00000   0.00000", Label.CENTER );

	text1.setFont( new Font( Font.MONOSPACED, Font.PLAIN, 14 ) );
	text2.setFont( new Font( Font.MONOSPACED, Font.PLAIN, 14 ) );
	text3.setFont( new Font( Font.MONOSPACED, Font.PLAIN, 14 ) );

	final Button apply = new Button( "Apply Transformation" );
	final Button cancel = new Button( "Cancel" );
	final Checkbox ignoreScale = new Checkbox( "Ignore scaling factor from BigDataViewer", ignoreScaling );

	/* Location */
	frame.setLayout( layout );

	c.fill = GridBagConstraints.HORIZONTAL;
	c.gridx = 0;
	c.gridy = 0;

	frame.add( text1, c );

	++c.gridy;
	frame.add( text2, c );

	++c.gridy;
	frame.add( text3, c );

	c.insets = new Insets( 20,0,0,0 );
	++c.gridy;
	frame.add( ignoreScale, c );

	c.insets = new Insets( 20,0,0,0 );
	++c.gridy;
	frame.add( apply, c );

	c.insets = new Insets( 0,0,0,0 );
	++c.gridy;
	frame.add( cancel, c );

	apply.addActionListener( new ApplyButtonListener( frame, bdv ) );
	cancel.addActionListener( new CancelButtonListener( frame, bdv ) );
	ignoreScale.addItemListener( new ItemListener(){ public void itemStateChanged( final ItemEvent arg0 ) { ignoreScaling = ignoreScale.getState(); } });

	frame.setVisible( true );

	timer = new Timer();
	timer.schedule( new BDVChecker( bdv, text1, text2, text3 ), 500 );
}