示例#1
0
  /**
   * Position the component of the GUI.
   *
   * <p>Currently use absolute positioning to gather most of the component in the top-left corner.
   */
  private void setLayout() {
    // Set the globe to use the full space available
    ping_globe.setBounds(0, 0, applet.getWidth(), applet.getHeight());

    // First raw of display
    Dimension name_size = nickname_field.getPreferredSize();
    Dimension update_name_size = rename_button.getPreferredSize();
    Dimension client_info_size = client_info_display.getPreferredSize();

    int row_height = name_size.height;

    nickname_field.setBounds(5, 5, name_size.width, row_height);

    rename_button.setBounds(8 + name_size.width, 5, update_name_size.width, row_height);

    client_info_display.setBounds(
        11 + name_size.width + update_name_size.width, 5, client_info_size.width, row_height);

    // Second raw of display
    Dimension counter_size = pings_counter_display.getPreferredSize();
    Dimension pause_size = pause_button.getMinimumSize();

    pings_counter_display.setBounds(5, 8 + row_height, counter_size.width, row_height);

    pause_button.setBounds(8 + counter_size.width, 8 + row_height, pause_size.width, row_height);
  }
示例#2
0
 /**
  * Updates the number of active voices.
  *
  * @param count The new number of active voices.
  */
 private void updateVoiceCount(int count) {
   Dimension d = lVoices.getPreferredSize();
   lVoices.setText(count == 0 ? "--" : String.valueOf(count));
   d = JuifeUtils.getUnionSize(d, lVoices.getPreferredSize());
   lVoices.setMinimumSize(d);
   lVoices.setPreferredSize(d);
   lVoices.setMaximumSize(d);
 }
示例#3
0
 private void setVolumeLabel(int volume) {
   Dimension d = lVolume.getPreferredSize();
   lVolume.setText(String.valueOf(volume) + '%');
   d = JuifeUtils.getUnionSize(d, lVolume.getPreferredSize());
   lVolume.setMinimumSize(d);
   lVolume.setPreferredSize(d);
   lVolume.setMaximumSize(d);
 }
示例#4
0
 @Override
 public void setDescription(JLabel label, String desc) {
   label.setText(String.format("<html>%s<html>", desc));
   label.setPreferredSize(null);
   label.setPreferredSize(
       new Dimension(
           fieldDimension.width,
           label.getPreferredSize().height
               * (label.getPreferredSize().width / fieldDimension.width + 1)));
 }
示例#5
0
  public SplashPanelV2(Icon image, String caption) {
    super(new BorderLayout());
    if (transparentSplash()) setBackground(new Color(255, 255, 255, 0));
    JPanel img_panel = new JPanel(new BorderLayout());
    JLabel img_label = new JLabel(image /* IconLoader.icon("splash3.png") */);
    if (transparentSplash()) img_panel.setBackground(new Color(255, 255, 255, 0));
    img_panel.add(img_label);

    txt_panel = new JPanel(new GridBagLayout());
    txt_panel.setBackground(Color.white);
    JLabel cap_label = new JLabel(caption /* "Version 1.0" */);
    cap_label.setFont(cap_label.getFont().deriveFont(java.awt.Font.BOLD, 20.0f));
    cap_label.setForeground(Color.lightGray);
    // make sure the version string is not wider than the logo img
    if (cap_label.getPreferredSize().width > img_label.getPreferredSize().width)
      cap_label.setPreferredSize(
          new Dimension(
              img_label.getPreferredSize().width - 20, cap_label.getPreferredSize().height));

    // replaced by progressmonitor below
    JLabel stat_label = new JLabel("some info");

    txt_panel.add(
        cap_label,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1,
            1,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 10),
            0,
            0));
    // txt_panel.add(stat_label, new GridBagConstraints(0, 1, 1, 1, 1, 1,
    // GridBagConstraints.EAST, GridBagConstraints.NONE,
    // new Insets(0, 10, 10, 10), 0, 0));

    // getContentPane().setBackground(new Color(255, 0, 0));
    // setBackground(new Color(0, 255, 0,127));
    // contents.setBackground(new Color(0, 0, 255,0));
    add(img_panel, BorderLayout.NORTH);
    add(txt_panel, BorderLayout.SOUTH);

    int alpha = transparentSplash() ? 0 : 255;
    setBorder(
        BorderFactory.createBevelBorder(
            BevelBorder.RAISED,
            new Color(255, 255, 255, alpha),
            new Color(255, 255, 255, alpha),
            new Color(103, 101, 98, alpha),
            new Color(148, 145, 140, alpha)));
  }
示例#6
0
 public void setBreakableWall() {
   ImageIcon im = new ImageIcon("brick.png");
   int height = im.getIconHeight();
   int win = 0;
   for (int i = 3 * height; i < sizex - height; i = i + height) {
     for (int j = 3 * height; j < sizey - height; j = j + height) {
       if (getMapState(i / BomborMan.unit, j / BomborMan.unit).getBlockType()
           != BlockType.UNBREKABLE) {
         if (Math.random() > 0.8) {
           final JLabel jl = new JLabel(im);
           gamePlay.add(jl);
           if (Math.random() > 0.3 && win == 0) {
             win = 1;
             winPos = new Position(i / BomborMan.unit, j / BomborMan.unit);
           }
           Dimension sizejl = jl.getPreferredSize();
           jl.setBounds(i, j, sizejl.width, sizejl.height);
           setMap(
               "brick.png",
               new Position(i / BomborMan.unit, j / BomborMan.unit),
               BlockType.BREAKABLE);
           posBrick.add(new Position(i / BomborMan.unit, j / BomborMan.unit));
           jlistBrick.add(jl);
         }
       }
     }
   }
 }
 /**
  * The class constructor.
  *
  * <p>Adds and creates a message saying bye.
  */
 public Instruction2() {
   setLayout(null);
   JButton back = new JButton(new ImageIcon("Back.png"));
   back.setOpaque(false);
   back.setContentAreaFilled(false);
   back.setBorderPainted(false);
   back.setFocusable(false);
   back.setRolloverIcon(new ImageIcon("Backrollover.png"));
   back.setActionCommand("Back");
   back.addActionListener(this);
   JLabel pic = new JLabel(new ImageIcon("Instructions2.png"));
   pic.setBounds(0, 0, pic.getPreferredSize().width, pic.getPreferredSize().height);
   back.setBounds(5, 200, back.getPreferredSize().width, back.getPreferredSize().height);
   add(pic);
   add(back);
 }
 /** Demo. */
 public static void main(String[] args) {
   try {
     JFrame frame = new JFrame("Panner");
     JPanel p = (JPanel) frame.getContentPane();
     URL url = PannerHandler.class.getResource("desert.jpg");
     String key =
         System.getProperty("os.name").toLowerCase().indexOf("mac") != -1 ? "\u2318" : "control";
     JLabel label =
         new JLabel("Press " + key + "+shift to display panner, click/drag to navigate");
     label.setBorder(new EmptyBorder(4, 4, 4, 4));
     p.add(label, BorderLayout.NORTH);
     JLabel image = new JLabel(new ImageIcon(url));
     image.setFocusable(true);
     PannerHandler handler = new PannerHandler(image, 95, new Point(0, 0));
     image.putClientProperty("panner", handler);
     p.add(new JScrollPane(image));
     frame.pack();
     Dimension size = image.getPreferredSize();
     size.width /= 2;
     size.height /= 2;
     Dimension ssize = frame.getToolkit().getScreenSize();
     frame.setLocation((ssize.width - size.width) / 2, (ssize.height - size.height) / 2);
     frame.setSize(size);
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     frame.setVisible(true);
     image.requestFocus();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
示例#9
0
  @Override
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    textLabel.setFont(table.getFont());
    textLabel.setText(Objects.toString(value, ""));
    textLabel.setBorder(hasFocus ? focusCellHighlightBorder : noFocusBorder);

    FontMetrics fm = table.getFontMetrics(table.getFont());
    Insets i = textLabel.getInsets();
    int swidth =
        iconLabel.getPreferredSize().width + fm.stringWidth(textLabel.getText()) + i.left + i.right;
    int cwidth = table.getColumnModel().getColumn(column).getWidth();
    dim.width = swidth > cwidth ? cwidth : swidth;

    if (isSelected) {
      textLabel.setOpaque(true);
      textLabel.setForeground(table.getSelectionForeground());
      textLabel.setBackground(table.getSelectionBackground());
      iconLabel.setIcon(sicon);
    } else {
      textLabel.setOpaque(false);
      textLabel.setForeground(table.getForeground());
      textLabel.setBackground(table.getBackground());
      iconLabel.setIcon(nicon);
    }
    return panel;
  }
 @Override
 public Dimension getPreferredSize() {
   if (getText().equals("")) {
     return (m_sizeLabel.getPreferredSize());
   }
   return (super.getPreferredSize());
 }
示例#11
0
  public FileNameRenderer(JTable table) {
    Border b = UIManager.getBorder("Table.noFocusBorder");
    if (Objects.isNull(b)) { // Nimbus???
      Insets i = focusCellHighlightBorder.getBorderInsets(textLabel);
      b = BorderFactory.createEmptyBorder(i.top, i.left, i.bottom, i.right);
    }
    noFocusBorder = b;

    p.setOpaque(false);
    panel.setOpaque(false);

    // http://www.icongalore.com/ XP Style Icons - Windows Application Icon, Software XP Icons
    nicon = new ImageIcon(getClass().getResource("wi0063-16.png"));
    sicon =
        new ImageIcon(
            p.createImage(
                new FilteredImageSource(nicon.getImage().getSource(), new SelectedImageFilter())));

    iconLabel = new JLabel(nicon);
    iconLabel.setBorder(BorderFactory.createEmptyBorder());

    p.add(iconLabel, BorderLayout.WEST);
    p.add(textLabel);
    panel.add(p, BorderLayout.WEST);

    Dimension d = iconLabel.getPreferredSize();
    dim.setSize(d);
    table.setRowHeight(d.height);
  }
 /**
  * Sets the preferred width of the title label. Use this function if you embed several data
  * constructor editor panels and want to align them.
  *
  * @param width the new preferred width
  */
 public void setTitleLabelWidth(int width) {
   Dimension prefSize = titleLabel.getPreferredSize();
   Insets insets = titleLabel.getInsets();
   titleLabel.setPreferredSize(
       new Dimension(
           width + insets.left + insets.right, prefSize.height + insets.top + insets.bottom));
 }
示例#13
0
  public PlayerPanel(ActionListener listener) {

    Dimension size;
    Insets in = this.getInsets();

    this.numberOfPlayersButtons = new ArrayList<JButton>(this.possiblePlayersAmount);
    this.colorButtons = new LinkedList<JButton>();

    label = new JLabel("Escolha a quantidade de jogadores:");
    this.add(label);

    size = label.getPreferredSize();
    label.setBounds(90, 5 + in.top, size.width, size.height);

    for (int i = 0; i < this.possiblePlayersAmount; i++) {

      JButton tempButton = new JButton(String.format("%d", i + 3));
      numberOfPlayersButtons.add(tempButton);

      size = tempButton.getPreferredSize();
      tempButton.setBounds(45 + 75 * i + in.left, 80 + in.top, size.width, size.height);
      tempButton.addActionListener(listener);

      this.add(tempButton);
    }

    this.setSize(this.getPreferredSize());
    this.setLayout(null);
    this.listener = listener;
  }
 public UnsupportedVideo(String url) {
   JLabel label = new JLabel(UIResourceManager.getIcon(UIResourceManager.ICON_ERROR));
   label.setToolTipText("The video could not be loaded: " + url);
   label.setHorizontalTextPosition(JLabel.CENTER);
   label.setVerticalTextPosition(JLabel.VERTICAL);
   label.setSize(label.getPreferredSize());
   component = label;
 }
示例#15
0
 protected JLabel createTitleLabel(int preferredWidth) {
   JLabel result = new JLabel(getTitle());
   result.setHorizontalAlignment(SwingConstants.CENTER);
   if (getIcon() != null) {
     result.setIcon(getIcon());
     result.setIconTextGap(10);
   }
   result.setBackground(titleBgColor);
   result.setForeground(titleForeColor);
   result.setOpaque(true);
   result.setBorder(titleBorder);
   result.validate();
   Dimension d = result.getPreferredSize();
   result.setPreferredSize(new Dimension(Math.max(d.width, preferredWidth), d.height));
   result.setMinimumSize(result.getPreferredSize());
   return result;
 }
    public SidebarOption(String labelTxt, String rsc) {
      label = new JLabel(labelTxt);
      label.setForeground(Color.WHITE);
      label.setFont(font);
      add(label);
      setOpaque(false);
      setMaximumSize(new Dimension(1000, label.getPreferredSize().height + 5));

      this.rsc = ClassLoader.getSystemClassLoader().getResource(rsc);
    }
示例#17
0
  public waitDialog(JDialog owner) {
    super(owner, "Chat Transcript Reader");

    this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    this.setLocationRelativeTo(null);
    this.getContentPane().setLayout(null);

    this.setPreferredSize(new Dimension(375, 75));

    JLabel info =
        new JLabel("<html>Please wait, retrieving chat transcripts from the server....<html>");
    info.setBounds(10, 10, info.getPreferredSize().width, info.getPreferredSize().height);
    this.getContentPane().add(info);

    // this.setModalityType(ModalityType.APPLICATION_MODAL);
    this.setAlwaysOnTop(true);
    this.setResizable(false);
    this.pack();
  }
示例#18
0
 /**
  * Draws this shape.
  *
  * @param g2 the graphics context
  */
 public void paintShape(Graphics2D g2) {
   Dimension dim = label.getPreferredSize();
   //        System.out.println(dim);
   if (dim.width > 0 && dim.height > 0) {
     label.setBounds(0, 0, dim.width, dim.height);
     g2.translate(getX(), getY());
     g2.scale(
         (image.getWidth() + 2 * xGrow) / dim.width, (image.getHeight() + 2 * yGrow) / dim.height);
     label.paint(g2);
   }
 }
示例#19
0
  /** Creates new form CoverScreen */
  public CoverScreen(CoverScreenData coverScreenData, Dimension dim) {
    this.coverScreenData = coverScreenData;
    initComponents();
    csp = new CoverScreenMainPanel();
    csp.addComponentListener(
        new ComponentAdapter() {

          public void componentResized(ComponentEvent e) {
            Insets insets = ((JPanel) e.getComponent()).getInsets();
            Dimension size = closeIcon.getPreferredSize();
            closeIcon.setBounds(
                (int) (((JPanel) e.getComponent()).getPreferredSize().getWidth() - size.width)
                    + insets.left,
                insets.top,
                size.width,
                size.height);
          }
        });
    csp.setLayout(null);
    closeIcon = new JLabel();
    csp.setPreferredSize(dim.getSize());
    closeIcon.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
    closeIcon.setLocation(100, 100);

    closeIcon.setHorizontalAlignment(JLabel.RIGHT);
    closeIcon.setPreferredSize(new Dimension(10, 17));
    closeIcon.setText("X");
    closeIcon.setOpaque(true);
    if (coverScreenData != null) {
      float[] comps = coverScreenData.getBackgroundColor().getColorArray();
      csp.setBackground(new Color(comps[0], comps[1], comps[2]));
    }
    csp.add(closeIcon);
    Insets insets = csp.getInsets();
    Dimension size = closeIcon.getPreferredSize();
    closeIcon.setBounds(
        (int) (csp.getPreferredSize().getWidth() - size.width) + insets.left,
        insets.top,
        size.width,
        size.height);
    jPanel1.add(csp, BorderLayout.CENTER);
    setPreferredSize(null);
    if (coverScreenData.getImageURL() != null && (!coverScreenData.getImageURL().equals(""))) {
      try {
        img =
            csp.scaleImage(
                AssetUtils.getAssetURL(coverScreenData.getImageURL()),
                (int) dim.getSize().getWidth(),
                (int) dim.getSize().getHeight());
      } catch (MalformedURLException ex) {
        Logger.getLogger(CoverScreen.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
示例#20
0
  public static void refreshCalendar(int month, int year) {
    // instantiation
    String[] months = {
      "January",
      "February",
      "March",
      "April",
      "May",
      "June",
      "July",
      "August",
      "September",
      "October",
      "November",
      "December"
    };
    int numoday, startom; // Number Of Days, Start Of Month

    // Allow/disallow buttons
    prev.setEnabled(true);
    next.setEnabled(true);
    if (month == 0 && year <= ryear) {
      prev.setEnabled(false);
    } // Cannot set an appointment back in time
    if (month == 11 && year >= ryear + 50) {
      next.setEnabled(false);
    } // Too early to set an appointment
    lmonth.setText(months[month]); // Refresh the month label (at the top)
    lmonth.setBounds(
        160 - lmonth.getPreferredSize().width / 2, 25, 180, 25); // Re-align label with calendar
    cyear.setSelectedItem(String.valueOf(year)); // Select the correct year in the combo box

    // deletes current table
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 7; j++) {
        mcal.setValueAt(null, i, j);
      }
    }

    // Get first day of month and number of days
    GregorianCalendar cal = new GregorianCalendar(year, month, 1);
    numoday = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
    startom = cal.get(GregorianCalendar.DAY_OF_WEEK);

    // Create calendar
    for (int i = 1; i <= numoday; i++) {
      int row = new Integer((i + startom - 2) / 7);
      int column = (i + startom - 2) % 7;
      mcal.setValueAt(i, row, column);
    }

    // Apply renderers
    Cal.setDefaultRenderer(Cal.getColumnClass(0), new tblCalendarRenderer());
  }
示例#21
0
  public static void refreshCalendar(int month, int year) {
    // Variables
    String[] months = {
      "January",
      "February",
      "March",
      "April",
      "May",
      "June",
      "July",
      "August",
      "September",
      "October",
      "November",
      "December"
    };
    int nod, som; // Number Of Days, Start Of Month

    // Allow/disallow buttons
    btnPrev.setEnabled(true);
    btnNext.setEnabled(true);
    if (month == 0 && year <= realYear - 10) {
      btnPrev.setEnabled(false);
    } // Too early
    if (month == 11 && year >= realYear + 100) {
      btnNext.setEnabled(false);
    } // Too late
    lblMonth.setText(months[month]); // Refresh the month label (at the top)
    lblMonth.setBounds(
        160 - lblMonth.getPreferredSize().width / 2, 25, 180, 25); // Re-align label with calendar
    cmbYear.setSelectedItem(String.valueOf(year)); // Select the correct year in the combo box

    // Clear table
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 7; j++) {
        mtblCalendar.setValueAt(null, i, j);
      }
    }

    // Get first day of month and number of days
    GregorianCalendar cal = new GregorianCalendar(year, month, 1);
    nod = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
    som = cal.get(GregorianCalendar.DAY_OF_WEEK);

    // Draw calendar
    for (int i = 1; i <= nod; i++) {
      int row = new Integer((i + som - 2) / 7);
      int column = (i + som - 2) % 7;
      mtblCalendar.setValueAt(i, row, column);
    }

    // Apply renderers
    tblCalendar.setDefaultRenderer(tblCalendar.getColumnClass(0), new tblCalendarRenderer());
  }
  public void setLabel() {
    int val = getValue();
    slide.setText(val + "");
    if (getOrientation() == JProgressBar.VERTICAL) {
      int lh = getBounds().height - (val * (getBounds().height) / getMaximum());
      slide.setBounds(0, lh, slide.getPreferredSize().width, slide.getPreferredSize().height);
    } else {
      double cent = (1.0 * getValue() / getMaximum());
      int k = 0;
      if (getValue() > 9) k = (new Integer(getValue())).toString().length();
      double xx = slide.getPreferredSize().width * (1.0 - 2 * cent + k / 3.0 * (cent - 1));
      int lh = (int) ((val * (1.0 * getBounds().width) / getMaximum()) + xx);

      slide.setBounds(
          lh,
          getBounds().height / 2 - slide.getPreferredSize().height / 2 - 2,
          slide.getPreferredSize().width,
          slide.getPreferredSize().height);
    }
  }
  private void processDrag(final MouseEvent e) {
    if (myDragCancelled) return;
    if (!isDraggingNow()) {
      if (myPressedPoint == null) return;
      if (isWithinDeadZone(e)) return;

      myDragPane = findLayeredPane(e);
      if (myDragPane == null) return;
      final BufferedImage image =
          new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
      paint(image.getGraphics());
      myDragButtonImage =
          new JLabel(new ImageIcon(image)) {

            public String toString() {
              return "Image for: " + StripeButton.this.toString();
            }
          };
      myDragPane.add(myDragButtonImage, JLayeredPane.POPUP_LAYER);
      myDragButtonImage.setSize(myDragButtonImage.getPreferredSize());
      setVisible(false);
      myPane.startDrag();
      myDragKeyEventDispatcher = new DragKeyEventDispatcher();
      KeyboardFocusManager.getCurrentKeyboardFocusManager()
          .addKeyEventDispatcher(myDragKeyEventDispatcher);
    }
    if (!isDraggingNow()) return;

    Point xy = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), myDragPane);
    if (myPressedPoint != null) {
      xy.x -= myPressedPoint.x;
      xy.y -= myPressedPoint.y;
    }
    myDragButtonImage.setLocation(xy);

    SwingUtilities.convertPointToScreen(xy, myDragPane);

    final Stripe stripe =
        myPane.getStripeFor(new Rectangle(xy, myDragButtonImage.getSize()), (Stripe) getParent());
    if (stripe == null) {
      if (myLastStripe != null) {
        myLastStripe.resetDrop();
      }
    } else {
      if (myLastStripe != null && myLastStripe != stripe) {
        myLastStripe.resetDrop();
      }
      stripe.processDropButton(this, myDragButtonImage, xy);
    }

    myLastStripe = stripe;
  }
示例#24
0
 private static int getTreeBaseline(JTree tree, int height) {
   int rowHeight = tree.getRowHeight();
   if (TREE_LABEL == null) {
     TREE_LABEL = new JLabel("X");
     TREE_LABEL.setIcon(UIManager.getIcon("Tree.closedIcon"));
   }
   JLabel label = TREE_LABEL;
   label.setFont(tree.getFont());
   if (rowHeight <= 0) {
     rowHeight = label.getPreferredSize().height;
   }
   return getLabelBaseline(label, rowHeight) + tree.getInsets().top;
 }
示例#25
0
  public void setBoundry() {
    ImageIcon im = new ImageIcon("hardbrick.png");
    int height = im.getIconHeight();

    for (int i = 0; i <= sizex - height; i = i + height) {
      final JLabel jl = new JLabel(im);
      gamePlay.add(jl);
      Dimension sizejl = jl.getPreferredSize();
      jl.setBounds(i, 0, sizejl.width, sizejl.height);
      setMap("hardbrick.png", new Position(i / BomborMan.unit, 0), BlockType.UNBREKABLE);
    }
    for (int i = 0; i <= sizex - height; i = i + height) {
      final JLabel jl = new JLabel(im);
      gamePlay.add(jl);
      Dimension sizejl = jl.getPreferredSize();
      jl.setBounds(i, BomborMan.sizeGlobal - height, sizejl.width, sizejl.height);
      setMap(
          "hardbrick.png",
          new Position(i / BomborMan.unit, (BomborMan.sizeGlobal - height) / BomborMan.unit),
          BlockType.UNBREKABLE);
    }
    for (int i = 0; i <= sizex - height; i = i + height) {
      final JLabel jl = new JLabel(im);
      gamePlay.add(jl);
      Dimension sizejl = jl.getPreferredSize();
      jl.setBounds(BomborMan.sizeGlobal - height, i, sizejl.width, sizejl.height);
      setMap(
          "hardbrick.png",
          new Position((BomborMan.sizeGlobal - height) / BomborMan.unit, i / BomborMan.unit),
          BlockType.UNBREKABLE);
    }
    for (int i = 0; i <= sizex - height; i = i + height) {
      final JLabel jl = new JLabel(im);
      gamePlay.add(jl);
      Dimension sizejl = jl.getPreferredSize();
      jl.setBounds(0, i, sizejl.width, sizejl.height);
      setMap("hardbrick.png", new Position(0, i / BomborMan.unit), BlockType.UNBREKABLE);
    }
  }
示例#26
0
 public void paintShape(Graphics2D g2) {
   if (color != null) {
     label.setForeground(
         new java.awt.Color((int) color.getRed(), (int) color.getGreen(), (int) color.getBlue()));
     Dimension dim = label.getPreferredSize();
     if (dim.width > 0 && dim.height > 0) {
       label.setBounds(0, 0, dim.width, dim.height);
       g2.translate(getX(), getY());
       g2.scale(getWidth() / dim.width, getHeight() / dim.height);
       label.paint(g2);
     }
   }
 }
示例#27
0
  public NewGameDialog(GUI parent) {
    this.parent = parent;
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    this.setTitle("New game");
    this.setSize(250, 150);
    this.setResizable(false);
    this.setLocationRelativeTo(null);
    JPanel contentPane = new JPanel();
    this.add(contentPane);
    contentPane.setLayout(new FlowLayout()); // BoxLayout(contentPane, BoxLayout.PAGE_AXIS));

    SpinnerNumberModel model = new SpinnerNumberModel(1, 1, 3, 1);
    JLabel numAIlabel = new JLabel("Number of opponents:");
    numAIlabel.setMaximumSize(numAIlabel.getPreferredSize());
    contentPane.add(numAIlabel);

    numAI = new JSpinner(model); /*{
            @Override
            public Dimension getMaximumSize() {
                Dimension dim = super.getMaximumSize();
                dim.height = getPreferredSize().height;
                return dim;
            }
        };*/
    numAI.setEditor(new JSpinner.DefaultEditor(numAI));
    numAI.setPreferredSize(new Dimension(100, 30));

    // numAI.setMaximumSize(numAI.getPreferredSize());

    contentPane.add(numAI);
    chooseDifficulty = new ButtonGroup();
    JRadioButton easy = new JRadioButton("Easy");
    JRadioButton intermediate = new JRadioButton("Intermediate");
    JRadioButton hard = new JRadioButton("Hard");
    easy.setActionCommand("EASY");
    intermediate.setActionCommand("INTERMEDIATE");
    hard.setActionCommand("HARD");
    chooseDifficulty.add(easy);
    chooseDifficulty.add(intermediate);
    chooseDifficulty.add(hard);
    contentPane.add(easy);
    contentPane.add(intermediate);
    contentPane.add(hard);
    easy.doClick();
    JButton confirm = new JButton("Confirm");
    contentPane.add(confirm);
    confirm.addActionListener(this);

    this.setVisible(true);
  }
 private void adjustTextLabelSize(JLabel label) {
     // Try to calculate a reasonable height
     Dimension oldPreferred = label.getPreferredSize();
     if (oldPreferred.width > maxTextWidth) {
         int numLines = oldPreferred.width / maxTextWidth + 1;
         if (numLines > maxTextLines) {
             numLines = maxTextLines;
         }
         oldPreferred.height *= numLines;
     }
     oldPreferred.width = maxTextWidth;
     label.setPreferredSize(oldPreferred);
     label.setMinimumSize(oldPreferred);
 }
示例#29
0
  @Override
  public void doLayout() {
    Dimension size = getSize();
    Insets insets = getInsets();
    int w = size.width - insets.left - insets.right;

    Dimension prefSize = introImage.getPreferredSize();
    introImage.setBounds(0, 0, prefSize.width, prefSize.height);

    if (introText.isVisible()) {
      prefSize = introText.getPreferredSize();
      introText.setBounds(introText.getX(), introText.getY(), prefSize.width, prefSize.height);
    }
  }
  private int preferredHeaderWidth() {
    JLabel longestRowLabel = new JLabel("65356#");
    if (m_width == 1) longestRowLabel = new JLabel("#");
    else if (m_width == 2) longestRowLabel = new JLabel("##");
    else if (m_width == 3) longestRowLabel = new JLabel("###");
    else if (m_width == 4) longestRowLabel = new JLabel("####");
    else if (m_width == 5) longestRowLabel = new JLabel("#####");

    JTableHeader header = table.getTableHeader();
    longestRowLabel.setBorder(header.getBorder());
    // UIManager.getBorder("TableHeader.cellBorder"));
    longestRowLabel.setHorizontalAlignment(JLabel.CENTER);
    longestRowLabel.setFont(header.getFont());
    return longestRowLabel.getPreferredSize().width;
  }