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

The following examples show how to use javax.swing.JLabel#setLocation() . These examples are extracted from open source projects. 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 Project: freecol   File: MapViewer.java    License: GNU General Public License v2.0 6 votes vote down vote up
private JLabel enterUnitOutForAnimation(final Unit unit,
                                        final Tile sourceTile) {
    Integer i = unitsOutForAnimation.get(unit);
    if (i == null) {
        final JLabel unitLabel = createUnitLabel(unit);
        unitLabel.setLocation(
            calculateUnitLabelPositionInTile(unitLabel.getWidth(),
                unitLabel.getHeight(),
                calculateTilePosition(sourceTile, false)));
        unitsOutForAnimationLabels.put(unit, unitLabel);
        getGUI().animationLabel(unitLabel, true);
        i = 1;
    } else {
        i++;
    }
    unitsOutForAnimation.put(unit, i);
    return unitsOutForAnimationLabels.get(unit);
}
 
Example 2
Source Project: moa   File: GraphCanvas.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void addEvents() {
    if (clusterEvents != null && clusterEvents.size() > eventCounter) {
        ClusterEvent ev = clusterEvents.get(eventCounter);
        eventCounter++;
        JLabel eventMarker = new JLabel(ev.getType().substring(0, 1));

        eventMarker.setPreferredSize(new Dimension(20, y_offset_top));
        eventMarker.setSize(new Dimension(20, y_offset_top));
        eventMarker.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        int x = (int) (ev.getTimestamp() / processFrequency / x_resolution);

        eventMarker.setLocation(x - 10, 0);
        eventMarker.setToolTipText(ev.getType() + " at " + ev.getTimestamp() + ": " + ev.getMessage());
        eventPanel.add(eventMarker);
        eventLabelList.add(eventMarker);
        eventPanel.repaint();
    }
}
 
Example 3
Source Project: moa   File: GraphCanvas.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void forceAddEvents() {
    if (clusterEvents != null) {
        eventPanel.removeAll();
        for (int i = 0; i < clusterEvents.size(); i++) {

            ClusterEvent ev = clusterEvents.get(i);
            JLabel eventMarker = new JLabel(ev.getType().substring(0, 1));

            eventMarker.setPreferredSize(new Dimension(20, y_offset_top));
            eventMarker.setSize(new Dimension(20, y_offset_top));
            eventMarker.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
            int x = (int) (ev.getTimestamp() / processFrequency / x_resolution);

            eventMarker.setLocation(x - 10, 0);
            eventMarker.setToolTipText(ev.getType() + " at " + ev.getTimestamp() + ": " + ev.getMessage());
            eventPanel.add(eventMarker);
            eventLabelList.add(eventMarker);
            eventPanel.repaint();
        }
    }
}
 
Example 4
public void init() {
		// Set background color to black
		setBackground(Color.black);
		// set desktop manager
		setDesktopManager(new MainDesktopManager());
		// Set component listener
		addComponentListener(this);
		// Create background label and set it to the back layer
		backgroundImageIcon = new ImageIcon();
		// Set up background
		backgroundLabel = new JLabel(backgroundImageIcon);
		// Add background
		add(backgroundLabel, Integer.MIN_VALUE);
		// Set location of background
		backgroundLabel.setLocation(0, 0);
		// Push the background to the back
		moveToBack(backgroundLabel);
		// Initialize firstDisplay to true
		firstDisplay = true;
		// Set background paper size
		setPreferredSize(new Dimension(InteractiveTerm.getWidth(), InteractiveTerm.getHeight()- 35));
		// Prep listeners
		prepareListeners();
		// Instantiate BrowserJFX
//		browserJFX = new BrowserJFX(this);
		// Create update thread.
		setupToolWindowTasks();
		// Prep tool windows
		prepareToolWindows();
		// Setup announcement window
		prepareAnnouncementWindow();
	}
 
Example 5
@Test
void locationRelativeTo() {
  final JLabel label = new JLabel();
  label.setLocation(new Point(10, 10));

  final Point defaultLocation =
      JFrameBuilder.builder().locateRelativeTo(label).build().getLocation();

  final Point relativeLocation = JFrameBuilder.builder().build().getLocation();

  assertThat(
      "location should change when setting position relative to another component",
      defaultLocation,
      not(equalTo(relativeLocation)));
}
 
Example 6
Source Project: chipster   File: SplashScreen.java    License: MIT License 5 votes vote down vote up
public SplashScreen(Icon icon) {
	frame = new JFrame();
	frame.setLayout(null);
	frame.setUndecorated(true);		
	frame.setSize(icon.getIconWidth(), icon.getIconHeight()+TEXT_HEIGHT);
	frame.setLocationRelativeTo(null);  
	frame.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
	frame.getRootPane().setBorder(new LineBorder(VisualConstants.SPLASH_BORDER_COLOR, 1));
	
	JLabel imageLabel = new JLabel(icon);
	imageLabel.setSize(icon.getIconWidth(), icon.getIconHeight());
	frame.add(imageLabel);
	imageLabel.setLocation(0, 0);
	textLabel = new JLabel();
	textLabel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
	
	textLabel.setFont(VisualConstants.SPLASH_SCREEN_FONT);
	
	textPanel = new JPanel(new BorderLayout());
	textPanel.setLocation(0, icon.getIconHeight());
	textPanel.setSize(icon.getIconWidth(), TEXT_HEIGHT);
	textPanel.setBackground(Color.WHITE);
	textPanel.setOpaque(true);
	textPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, VisualConstants.SPLASH_BORDER_COLOR));
	textPanel.add(textLabel);
	
	frame.add(textPanel);
	frame.setVisible(true);
}
 
Example 7
Source Project: SikuliX1   File: SxHotspot.java    License: MIT License 4 votes vote down vote up
public SxHotspot(Region region, Visual text, Guide g) {
  super(region);
  guide = g;
  spotlight = new SxSpotlight(region);
  spotlight.setShape(SxSpotlight.CIRCLE);

  Rectangle bounds = spotlight.getBounds();
  bounds.grow(10, 10);
  spotlight.setBounds(bounds);

  this.text = text;
  text.setLocationRelativeToComponent(this, Layout.RIGHT);
  //this.text.setLocationRelativeToRegion(new Region(bounds), Visual.RIGHT);

  // draw a question mark centered on the region
  Font f = new Font("sansserif", Font.BOLD, 18);
  symbol = new JLabel("?");
  symbol.setFont(f);
  Dimension size = symbol.getPreferredSize();
  symbol.setSize(size);
  symbol.setForeground(Color.white);
  symbol.setLocation(region.x + region.w / 2 - size.width / 2,
          region.y + region.h / 2 - size.height / 2);

  // draw a circle around the question mark
  Rectangle cc = new Rectangle(symbol.getBounds());
  cc.grow(7, 0);
  circle = new SxCircle(new Region(cc));
  circle.setForeground(Color.white);
  circle.setShadow(5, 2);

  g.content.add(symbol);
  g.addToFront(circle);

  g.addToFront(spotlight);
  g.addToFront(text);

  text.setVisible(false);
  spotlight.setVisible(false);

}
 
Example 8
/**
 * {@inheritDoc}
 */
@Override
public void executeWithUnitOutForAnimation(JLabel unitLabel) {
    final GUI gui = getGUI();
    final float scale = gui.getAnimationScale();
    final int movementRatio = (int)(Math.pow(2, this.speed + 1) * scale);
    final Rectangle r1 = gui.getAnimationTileBounds(this.sourceTile);
    final Rectangle r2 = gui.getAnimationTileBounds(this.destinationTile);
    final Rectangle bounds = r1.union(r2);
    final double xratio = ImageLibrary.TILE_SIZE.width
        / (double)ImageLibrary.TILE_SIZE.height;

    // Tile positions should be valid at this point.
    final Point srcP = gui.getAnimationTilePosition(this.sourceTile);
    if (srcP == null) {
        logger.warning("Failed move animation for " + this.unit
            + " at source tile: " + this.sourceTile);
        return;
    }
    final Point dstP = gui.getAnimationTilePosition(this.destinationTile);
    if (dstP == null) {
        logger.warning("Failed move animation for " + this.unit
            + " at destination tile: " + this.destinationTile);
        return;
    }
        
    final int labelWidth = unitLabel.getWidth();
    final int labelHeight = unitLabel.getHeight();
    final Point srcPoint = gui.getAnimationPosition(labelWidth, labelHeight, srcP);
    final Point dstPoint = gui.getAnimationPosition(labelWidth, labelHeight, dstP);
    final int stepX = (int)Math.signum(dstPoint.getX() - srcPoint.getX());
    final int stepY = (int)Math.signum(dstPoint.getY() - srcPoint.getY());

    Point point = srcPoint;
    long time = now(), dropFrames = 0;
    while (!point.equals(dstPoint)) {
        point.x += stepX * xratio * movementRatio;
        point.y += stepY * movementRatio;
        if ((stepX < 0 && point.x < dstPoint.x)
            || (stepX > 0 && point.x > dstPoint.x)) {
            point.x = dstPoint.x;
        }
        if ((stepY < 0 && point.y < dstPoint.y)
            || (stepY > 0 && point.y > dstPoint.y)) {
            point.y = dstPoint.y;
        }
        if (dropFrames <= 0) {
            unitLabel.setLocation(point);
            gui.paintImmediately(bounds);
            long newTime = now();
            long timeTaken = newTime - time;
            time = newTime;
            final long waitTime = ANIMATION_DELAY - timeTaken;
            if (waitTime > 0) {
                delay(waitTime, "Animation interrupted.");
                dropFrames = 0;
            } else {
                dropFrames = timeTaken / ANIMATION_DELAY - 1;
            }
        } else {
            dropFrames--;
        }
    }
    gui.refresh();
}
 
Example 9
Source Project: Java   File: MainFrame.java    License: Artistic License 2.0 4 votes vote down vote up
private static void move(JLabel c, int vMoveType, int hMoveType) {
	c.setLocation(c.getX() - hMoveType * 50, c.getY() - vMoveType * 50);
}
 
Example 10
public LoadingPanel(){
    JLabel loadingLabel = new JLabel("OSRS Loading, please wait.\nThank you for choosing Luna!");
    loadingLabel.setLocation(200,765/2);
    add(loadingLabel);
    
}
 
Example 11
Source Project: java-QQ-   File: erweima_panel.java    License: Apache License 2.0 2 votes vote down vote up
public void run()
{     
	JLabel  erweimabg1_2=new JLabel(new ImageIcon("image/erweimabg1.png"));
    erweimabg1_2.setBounds(89,150, 129,123);

	while (true)
	{
		
		
		pic2_x=erweimabg1_2.getBounds().x;
		pic2_y=erweimabg1_2.getBounds().y;
		
		for( i=pic2_x,j=pic2_y;i<=155;i=i+6)
		{
		    	
				
		
			    erweimabg1.setVisible(false);
			    erweimabg2.setVisible(false);
			    
				erweimabg1_2.setLocation(i, j);
				con.add(erweimabg1_2);
				
				con.add(bg);
			    con.repaint();
		//		System.out.println(threadbg_y);
				try
				{
					Thread.sleep(6);
				}
				catch(InterruptedException e)
				{
					e.printStackTrace();
				}

                    //    System.out.println(i);
                        if(pic2_x>=155)
						{
									
							 return;	
								    
				     	}	
					     
		    } 
		  
	
			
		
			
			
		}
		
		
	}