Java Code Examples for javax.swing.JLabel#setLocation()
The following examples show how to use
javax.swing.JLabel#setLocation() .
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: MapViewer.java From freecol with GNU General Public License v2.0 | 6 votes |
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 File: GraphCanvas.java From moa with GNU General Public License v3.0 | 6 votes |
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 File: GraphCanvas.java From moa with GNU General Public License v3.0 | 6 votes |
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
Source File: MainDesktopPane.java From mars-sim with GNU General Public License v3.0 | 5 votes |
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
Source File: JFrameBuilderTest.java From triplea with GNU General Public License v3.0 | 5 votes |
@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 File: SplashScreen.java From chipster with MIT License | 5 votes |
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 File: SxHotspot.java From SikuliX1 with MIT License | 4 votes |
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
Source File: UnitMoveAnimation.java From freecol with GNU General Public License v2.0 | 4 votes |
/** * {@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 File: MainFrame.java From Java with Artistic License 2.0 | 4 votes |
private static void move(JLabel c, int vMoveType, int hMoveType) { c.setLocation(c.getX() - hMoveType * 50, c.getY() - vMoveType * 50); }
Example 10
Source File: LoadingPanel.java From osrsclient with GNU General Public License v2.0 | 4 votes |
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 File: erweima_panel.java From java-QQ- with Apache License 2.0 | 2 votes |
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; } } } }