コード例 #1
0
 public String getNameFieldText() {
   String shapeName = nameField.getText();
   if (shapeName == null) {
     return "";
   } else {
     shapeName = shapeName.trim();
   }
   return shapeName;
 }
コード例 #2
0
  private void initComponents() {
    setLayout(null);

    JPanel controlPanel = new JPanel();
    controlPanel.setLayout(null);
    controlPanel.setBorder(
        BorderFactory.createCompoundBorder(
            new EtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(5, 5, 5, 5)));
    controlPanel.setBounds(5, 5, 190, 385);

    JLabel nameLabel = new JLabel("Shape Name:");
    nameLabel.setBounds(10, 5, 170, 25);
    controlPanel.add(nameLabel);

    nameField = new TextFieldWithPlaceHolder("Please enter a shape name", StringType.PLACEHOLDER);
    nameField.setBounds(10, 30, 170, 25);
    controlPanel.add(nameField);

    JLabel resolutionLabel = new JLabel("Grid resolution:");
    resolutionLabel.setBounds(10, 55, 170, 25);
    controlPanel.add(resolutionLabel);

    resolution = new JComboBox<Vec2>(this.getComboModel());
    resolution.setMaximumRowCount(30);
    currentResolutionSelection = resolution.getSelectedIndex();
    resolution.setBounds(10, 80, 170, 25);
    resolution.setRenderer(
        new ListCellRenderer<Vec2>() {
          JLabel resoLabel = null;

          @Override
          public Component getListCellRendererComponent(
              JList<? extends Vec2> list,
              Vec2 value,
              int index,
              boolean isSelected,
              boolean cellHasFocus) {
            if (resoLabel == null) {
              resoLabel = new JLabel();
              resoLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 1, 0));
            }
            resoLabel.setText((int) value.x + "x" + (int) value.y);
            if (isSelected) {
              resoLabel.setBackground(list.getSelectionBackground());
              resoLabel.setForeground(list.getSelectionForeground());
            } else {
              resoLabel.setBackground(list.getBackground());
              resoLabel.setForeground(list.getForeground());
            }
            return resoLabel;
          }
        });
    controlPanel.add(resolution);

    JLabel colorLabel = new JLabel("Choose color:");
    colorLabel.setBounds(10, 115, 145, 25);
    controlPanel.add(colorLabel);

    colorButton = new JButton();
    colorButton.setBackground(Color.green);
    buildPanel.setPaintColor(colorButton.getBackground());
    colorButton.setBounds(155, 115, 25, 25);
    controlPanel.add(colorButton);

    saveButton = new JButton("Save"); // TODO

    add(controlPanel);
  }