Example usage for javax.swing JLabel setLocation

List of usage examples for javax.swing JLabel setLocation

Introduction

In this page you can find the example usage for javax.swing JLabel setLocation.

Prototype

public void setLocation(int x, int y) 

Source Link

Document

Moves this component to a new location.

Usage

From source file:Main.java

public static void main(String... args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel contentPane = new JPanel();
    contentPane.setOpaque(true);//w w w .ja  v a 2s . c  o  m
    contentPane.setBackground(Color.WHITE);
    contentPane.setLayout(null);

    JLabel label = new JLabel("This JPanel uses Absolute Positioning", JLabel.CENTER);
    label.setSize(300, 30);
    label.setLocation(5, 5);

    JButton button = new JButton("USELESS");
    button.setSize(100, 30);
    button.setLocation(95, 45);

    contentPane.add(label);
    contentPane.add(button);

    frame.setContentPane(contentPane);
    frame.setSize(310, 125);
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}

From source file:org.encog.workbench.dialogs.common.ChartField.java

public int createField(JPanel panel, int x, int y, int width) {
    this.chartHolder = new JPanel();

    XYDataset dataset = generator.createDataset();
    JFreeChart chart = generator.createChart(dataset);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartHolder.setLayout(new BorderLayout());
    chartHolder.add(chartPanel, BorderLayout.CENTER);
    chartHolder.add(this.refreshButton = new JButton("Refresh Chart"), BorderLayout.SOUTH);

    this.refreshButton.addActionListener(this);
    this.setField(chartHolder);

    this.getField().setLocation(5, y);
    this.getField().setSize(this.getOwner().getWidth() - 5, height);

    JLabel label = createLabel();
    label.setVisible(false);//from   w ww  . j a  v  a2s.  com
    label.setLocation(label.getX(), y);
    panel.add(label);
    panel.add(this.getField());

    return y + this.getField().getHeight();
}

From source file:neironweb.Frame.java

public Frame() {
    super("neural network");
    //JPanel pane = new JPanel();

    setLayout(null);//from  ww  w .j ava 2s.  c  o m

    JPanel mailPanel = new JPanel();
    mailPanel.setLayout(null);
    mailPanel.setLocation(50, 30);
    mailPanel.setSize(300, 170);
    mailPanel.setBorder(BorderFactory.createLineBorder(Color.black));

    JLabel mailLabel = new JLabel("e-mail:");
    mailLabel.setLocation(10, 10);
    mailLabel.setSize(50, 30);
    mailPanel.add(mailLabel);

    JLabel dirMailLabel = new JLabel("direct:");
    dirMailLabel.setLocation(10, 50);
    dirMailLabel.setSize(50, 30);
    mailPanel.add(dirMailLabel);

    JTextField mailField = new JTextField("mail@mail.ru");
    mailField.setSize(150, 30);
    mailField.setLocation(80, 10);
    mailPanel.add(mailField);

    JTextField textField = new JTextField("INBOX");
    textField.setLocation(80, 50);
    textField.setSize(150, 30);
    mailPanel.add(textField);

    JButton mailButton = new JButton("Analyze");
    mailButton.setLocation(80, 90);
    mailButton.setSize(150, 30);
    mailPanel.add(mailButton);

    //        JButton eduButton = new JButton("Start education");
    //        eduButton.setLocation(0, 50);
    //        eduButton.setSize(150, 30);
    //        buttonPanel.add(eduButton);

    XYSeries xyser = new XYSeries("");
    XYDataset xy = new XYSeriesCollection(xyser);
    JFreeChart jf = ChartFactory.createXYLineChart("Education", "X", "Y", xy);

    for (int i = 0; i < 100; i++)
        xyser.add(i, Math.cos(i));

    ChartPanel chartPanel = new ChartPanel(jf);
    chartPanel.setSize(700, 300);
    chartPanel.setLocation(50, 230);
    chartPanel.setBorder(BorderFactory.createLineBorder(Color.black));

    //        JPanel myChartPanel = new JPanel();        
    //        myChartPanel.setLayout(null);
    //        myChartPanel.setLocation(50, 230);
    //        myChartPanel.setSize(700, 300);
    //        myChartPanel
    //      myChartPanel.add(chartPanel);        

    setSize(800, 600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container con = this.getContentPane(); // inherit main frame
    //con.add(pane); 
    con.add(mailPanel);
    //con.add(myChartPanel);
    con.add(chartPanel);
    setVisible(true);

}

From source file:Main.java

public Main() {
    mainPanel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
    mainPanel.setLayout(null);// ww  w .j  ava  2 s  .com

    MyMouseAdapter myMouseAdapter = new MyMouseAdapter();
    for (int i = 0; i < LABEL_STRINGS.length; i++) {
        JLabel label = new JLabel(LABEL_STRINGS[i], SwingConstants.CENTER);
        label.setSize(new Dimension(LBL_WIDTH, LBL_HEIGHT));
        label.setOpaque(true);
        Random random = new Random();
        label.setLocation(random.nextInt(WIDTH - LBL_WIDTH), random.nextInt(HEIGHT - LBL_HEIGHT));
        label.setBackground(
                new Color(150 + random.nextInt(105), 150 + random.nextInt(105), 150 + random.nextInt(105)));
        label.addMouseListener(myMouseAdapter);
        label.addMouseMotionListener(myMouseAdapter);

        mainPanel.add(label);
    }
}

From source file:net.sf.firemox.ui.component.SplashScreen.java

/**
 * Create a new instance of this class.//from   w  w  w . ja  v  a  2s.  c om
 * 
 * @param filename
 *          the picture filename.
 * @param parent
 *          the splash screen's parent.
 * @param waitTime
 *          the maximum time before the screen is hidden.
 */
public SplashScreen(String filename, Frame parent, int waitTime) {
    super(parent);
    getContentPane().setLayout(null);
    toFront();
    final JLabel l = new JLabel(new ImageIcon(filename));
    final Dimension labelSize = l.getPreferredSize();
    l.setLocation(0, 0);
    l.setSize(labelSize);
    setSize(labelSize);

    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation(screenSize.width / 2 - labelSize.width / 2, screenSize.height / 2 - labelSize.height / 2);

    final JLabel mp = new JLabel(IdConst.PROJECT_DISPLAY_NAME);
    mp.setLocation(30, 305);
    mp.setSize(new Dimension(300, 30));

    final JLabel version = new JLabel(IdConst.VERSION);
    version.setLocation(235, 418);
    version.setSize(new Dimension(300, 30));

    final JTextArea disclaimer = new JTextArea();
    disclaimer.setEditable(false);
    disclaimer.setLineWrap(true);
    disclaimer.setWrapStyleWord(true);
    disclaimer.setAutoscrolls(true);
    disclaimer.setFont(MToolKit.defaultFont);
    disclaimer.setTabSize(2);

    // Then try and read it locally
    Reader inGPL = null;
    try {
        inGPL = new BufferedReader(new InputStreamReader(MToolKit.getResourceAsStream(IdConst.FILE_LICENSE)));
        disclaimer.read(inGPL, "");
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(inGPL);
    }

    final JScrollPane disclaimerSPanel = new JScrollPane();
    disclaimerSPanel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    disclaimerSPanel.setViewportView(disclaimer);
    disclaimerSPanel.setLocation(27, 340);
    disclaimerSPanel.setPreferredSize(new Dimension(283, 80));
    disclaimerSPanel.setSize(disclaimerSPanel.getPreferredSize());

    getContentPane().add(disclaimerSPanel);
    getContentPane().add(version);
    getContentPane().add(mp);
    getContentPane().add(l);

    final int pause = waitTime;
    final Runnable waitRunner = new Runnable() {
        public void run() {
            try {
                Thread.sleep(pause);
                while (!bKilled) {
                    Thread.sleep(200);
                }
            } catch (InterruptedException e) {
                // Ignore this error
            }
            setVisible(false);
            dispose();
            MagicUIComponents.magicForm.toFront();
        }
    };

    // setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            setVisible(false);
            dispose();
            if (MagicUIComponents.magicForm != null)
                MagicUIComponents.magicForm.toFront();
        }
    });
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                setVisible(false);
                dispose();
                MagicUIComponents.magicForm.toFront();
            }
        }
    });
    setVisible(true);
    start(waitRunner);
}

From source file:Main.java

@Override
public void mouseDragged(MouseEvent e) {
    if (initLabelLocation == null || initMouseLocationOnScreen == null) {
        return;//from  w  w  w. j a  v a  2 s  . c om
    }
    JLabel label = (JLabel) e.getSource();
    Point mouseLocation = e.getLocationOnScreen();
    int deltaX = mouseLocation.x - initMouseLocationOnScreen.x;
    int deltaY = mouseLocation.y - initMouseLocationOnScreen.y;
    int labelX = initLabelLocation.x + deltaX;
    int labelY = initLabelLocation.y + deltaY;
    label.setLocation(labelX, labelY);
}

From source file:cn.edu.tsinghua.gui.HistogramDemo.java

/**
 * Initialize display.// w w w  .j  a  va  2s .c om
 * @author Sun Microsystems
 * @param filename is the image filename
 */
public HistogramDemo(String filename) {
    File f = new File(filename);

    if (f.exists() && f.canRead()) {
        source = JAI.create("fileload", filename);
    } else {
        return;
    }

    canvas = new ImageDisplay(source);
    canvas.setLayout(new FlowLayout(FlowLayout.RIGHT, 2, 2));

    panner = new Panner(canvas, source, 128);
    panner.setBackground(Color.red);
    panner.setBorder(new EtchedBorder());
    canvas.add(panner);

    Font font = new Font("SansSerif", Font.BOLD, 12);
    JLabel title = new JLabel(" Histogram");
    title.setFont(font);
    title.setLocation(0, 32);

    setOpaque(true);
    setLayout(new BorderLayout());
    setBackground(Color.white);

    graph = new XYPlot();
    graph.setBackground(Color.black);
    graph.setBorder(new LineBorder(new Color(0, 0, 255), 1));

    Colorbar cbar = new Colorbar();
    cbar.setBackground(Color.black);
    cbar.setPreferredSize(new Dimension(256, 25));
    cbar.setBorder(new LineBorder(new Color(255, 0, 255), 2));

    JPanel hist_panel = new JPanel();
    hist_panel.setLayout(new BorderLayout());
    hist_panel.setBackground(Color.white);
    hist_panel.add(graph, BorderLayout.CENTER);
    hist_panel.add(cbar, BorderLayout.SOUTH);

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(2, 1, 5, 5));
    panel.setBackground(Color.white);
    panel.add(canvas);
    panel.add(hist_panel);

    JPanel controlPanel = new JPanel();
    controlPanel.setLayout(new FlowLayout());

    reset = new JButton("Reset");
    equal = new JButton("Uniform");
    norm = new JButton("Gaussian");
    piece = new JButton("Piecewise");

    reset.addActionListener(this);
    equal.addActionListener(this);
    norm.addActionListener(this);
    piece.addActionListener(this);

    controlPanel.add(reset);
    controlPanel.add(equal);
    controlPanel.add(norm);
    controlPanel.add(piece);

    add(title, BorderLayout.NORTH);
    add(panel, BorderLayout.CENTER);
    add(controlPanel, BorderLayout.SOUTH);

    // original histogram (remains unmodified)
    // graph.plot( getHistogram(source) );
    graph.plot(getMultiHistogram(source));
}

From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java

/**
 * Displays Splash Screen// w  ww.  ja  va 2 s  .  co m
 * 
 * @return Splash Screen Reference
 */
public static JWindow showSplash() {

    JWindow splash = new JWindow();
    splash.setSize(400, 250);
    splash.setLayout(null);

    JLabel status = new JLabel("Developed by Yohan Liyanage, 2008");
    JLabelAppender.setLabel(status);
    status.setFont(new Font("sansserif", Font.PLAIN, 10));
    status.setSize(350, 30);
    status.setLocation(10, 220);
    splash.add(status);

    JLabel lbl = new JLabel(
            new ImageIcon(ClassLoader.getSystemResource("META-INF/resources/nebula-startup.png")));
    lbl.setSize(400, 250);
    lbl.setLocation(0, 0);
    splash.add(lbl);

    splash.setVisible(true);
    splash.setLocationRelativeTo(null);

    return splash;
}

From source file:battleheartlegacybuilder.mainWindow.java

private void buildGridskills() {
    int xPosition = 0;
    int nextRow = 0;

    for (int i = 0; i < notPassiveSkillsNumber; i++) {
        JLabel label = new JLabel("");
        label.setSize(50, 50);/* www . j  av  a2s.c om*/
        if (i == 4 || i == 8) {
            nextRow += 60;
            xPosition = 0;
        }
        label.setLocation((xPosition * 60) + 5, 30 + nextRow);
        xPosition++;

        label.setIcon(new javax.swing.ImageIcon(
                getClass().getResource("/media/images/OtherImages/skillNotSlected.png")));
        this.pnl_skillsGrids.add(label);
        ingameClassLabelsSkills.add(label);
    }
}

From source file:edu.clemson.cs.nestbed.client.gui.MoteManagementPanel.java

public MoteManagementPanel(MoteTestbedAssignment mtbAssignment, ProgramManager programManager,
        int projDepConfID, MoteManager moteManager, MoteTypeManager moteTypeManager,
        MoteDeploymentConfigurationManager mdcManager)
        throws RemoteException, NotBoundException, MalformedURLException {

    lookupRemoteManagers();//w  w w  .ja  v a 2s.c  o  m

    this.programManager = programManager;
    this.mtbAssignment = mtbAssignment;
    this.projDepConfID = projDepConfID;
    this.mote = moteManager.getMote(mtbAssignment.getMoteID());
    this.moteType = moteTypeManager.getMoteType(mote.getMoteTypeID());
    this.mdcManager = mdcManager;
    this.moteDepConfig = mdcManager.getMoteDeploymentConfiguration(projDepConfID, mote.getID());

    setIcon(new ImageIcon(moteType.getImage()).getImage());

    if (this.moteDepConfig != null) {
        this.program = programManager.getProgram(moteDepConfig.getProgramID());
    }

    Dimension labelSize = new Dimension(LABEL_WIDTH, LABEL_HEIGHT);
    JLabel addressLabel = new JLabel("" + mtbAssignment.getMoteAddress());
    addressLabel.setSize(labelSize);
    addressLabel.setPreferredSize(labelSize);

    setToolTipText(getToolTipString());
    addMouseListener(new MotePanelMouseListener());

    add(addressLabel);
    addressLabel.setLocation(2, 0);

    progDeployMgr.addRemoteObserver(new ProgramInstallationObserver());
    mdcManager.addRemoteObserver(new MoteDeploymentConfigObserver());
}