コード例 #1
0
ファイル: ReviewDialog.java プロジェクト: rokstrnisa/RokClock
 /**
  * This function re-computes the total number of hours for the selected period. It is ran every
  * time the user edits a text field specifying the number of hours for a particular top-level
  * project. Percentage labels are also updated.
  */
 private void recomputeTotal() {
   double total = 0;
   for (Row row : rows.values()) {
     try {
       row.hours = Double.parseDouble(row.hoursTF.getText());
       total += row.hours;
       row.hoursTF.setForeground(normalColour);
     } catch (NumberFormatException e) {
       row.hoursTF.setForeground(errorColour);
       totalLabel.setText("ERROR");
       totalLabel.setForeground(errorColour);
       return;
     }
   }
   totalLabel.setText(decimalFormat.format(total));
   totalLabel.setForeground(normalColour);
   for (Row row : rows.values()) {
     String percentS = decimalFormat.format(total == 0 ? 0 : 100 * row.hours / total);
     row.percentL.setText("(" + percentS + "%)");
   }
   pack();
 }
コード例 #2
0
ファイル: MainPanel.java プロジェクト: mhcrnl/java-swing-tips
  private MainPanel() {
    super();

    JLabel label = new JLabel(new DragHereIcon());
    label.setText("<html>Drag <b>Files</b> Here");
    label.setVerticalTextPosition(SwingConstants.BOTTOM);
    label.setHorizontalTextPosition(SwingConstants.CENTER);
    label.setForeground(Color.GRAY);
    label.setFont(new Font(Font.SERIF, Font.PLAIN, 24));

    label.setDropTarget(
        new DropTarget(label, DnDConstants.ACTION_COPY, new FileDropTargetAdapter(), true));
    // Test: label.setTransferHandler(new FileTransferHandler());

    add(label);
    setPreferredSize(new Dimension(320, 240));
  }