Example #1
0
 private void setGbc(GridBagConstraints gbc, int x, int y, int w, int h) {
   gbc.gridx = x;
   gbc.gridy = y;
   gbc.gridwidth = w;
   gbc.gridheight = h;
 }
Example #2
0
  ShutdownFrame(CryoBay cb) {
    super("CryoBay Monitor");
    cryoB = cb;

    cmdClose =
        new JButton("Close") {
          public JToolTip createToolTip() {
            return new JToolTip();
          }
        };

    cmdClose.setToolTipText("Close program");

    cmdClose.addActionListener(this);
    addWindowListener(this);

    GridBagConstraints gbc = new GridBagConstraints();
    Border loweredbevel = BorderFactory.createLoweredBevelBorder();

    lblBStatus = new JLabel("Status: ");
    lblBHeater = new JLabel("Heater: ");
    lblBTemp = new JLabel("  Temp: ");
    lblBCli = new JLabel("   CLI: ");

    lblStatus = new JTextField(17);
    lblStatus.setEditable(false);
    lblStatus.setOpaque(true);
    lblStatus.setBorder(loweredbevel);

    lblHeater = new JTextField(17);
    lblHeater.setEditable(false);
    lblHeater.setOpaque(true);
    lblHeater.setBorder(loweredbevel);

    lblTemp = new JTextField(17);
    lblTemp.setEditable(false);
    lblTemp.setOpaque(true);
    lblTemp.setBorder(loweredbevel);

    lblCli = new JTextField(17);
    lblCli.setEditable(false);
    lblCli.setOpaque(true);
    lblCli.setBorder(loweredbevel);

    JPanel lblPanel = new JPanel();
    lblPanel.setLayout(new GridBagLayout());
    gbc.insets = new Insets(2, 5, 2, 5);
    setGbc(gbc, 0, 0, 1, 1);
    lblPanel.add(lblBStatus, gbc);
    setGbc(gbc, 0, 1, 1, 1);
    lblPanel.add(lblBHeater, gbc);
    setGbc(gbc, 0, 2, 1, 1);
    lblPanel.add(lblBTemp, gbc);
    setGbc(gbc, 0, 3, 1, 1);
    lblPanel.add(lblBCli, gbc);

    JPanel valPanel = new JPanel();
    valPanel.setLayout(new GridBagLayout());
    gbc.insets = new Insets(2, 5, 2, 5);
    setGbc(gbc, 0, 0, 1, 1);
    valPanel.add(lblStatus, gbc);
    setGbc(gbc, 0, 1, 1, 1);
    valPanel.add(lblHeater, gbc);
    setGbc(gbc, 0, 2, 1, 1);
    valPanel.add(lblTemp, gbc);
    setGbc(gbc, 0, 3, 1, 1);
    valPanel.add(lblCli, gbc);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    gbc.anchor = GridBagConstraints.CENTER;
    setGbc(gbc, 0, 5, 1, 1);
    buttonPanel.add(cmdClose, gbc);

    // finally, add the panels to the content pane
    getContentPane().setLayout(new GridBagLayout());
    gbc.insets = new Insets(10, 10, 10, 10);
    gbc.anchor = GridBagConstraints.CENTER;
    setGbc(gbc, 0, 0, 1, 4);
    getContentPane().add(lblPanel, gbc);
    setGbc(gbc, 1, 0, 1, 4);
    getContentPane().add(valPanel, gbc);
    setGbc(gbc, 0, 5, 0, 0);
    getContentPane().add(buttonPanel, gbc);

    setSize(300, 220);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation(screenSize.width / 2 - 300, screenSize.height / 2 - 220);
    setResizable(true);
  }