Пример #1
1
 public void paint(Graphics g) {
   imageLabel.setLocation(textField.getX() - 8, 2);
   super.paint(g);
   //    System.out.println( "panel paint" ) ;
 }
Пример #2
0
  /** creates a JTextfield with JLabel (contains labelText) and an identifier id */
  public TLangTextField(String labelText, int id, FieldPopup popup) {
    super();

    //    this.setOpaque( false ) ;
    this.setLayout(new OverlayLayout(this));
    //    this.setBorder( BorderFactory.createEtchedBorder());

    listenerList = new EventListenerList();

    // build the labeled textfield --------------------------------------------
    textField =
        new IDTextField(id, popup) {
          public void paint(Graphics g) {
            super.paint(g);

            if (currentImage != null) {
              Graphics2D g2 = (Graphics2D) g;
              g2.drawImage(currentImage, -8, -2, this);
            }

            //        System.out.println( "paint " +(counter++) ) ;
          }
        };

    textField.addKeyListener(this);
    textField.addFocusListener(this);
    textField.setPopupName(labelText);
    textField.setMaximumSize(new Dimension(2000, 30));
    textField.setFont(GUIGlobals.defaultLanguageFont);

    // charat position
    leerInsets = textField.getMargin();

    label = new JLabel(labelText, JLabel.TRAILING);
    label.setLabelFor(textField);
    label.addFocusListener(this);

    // insert label and textfield
    layout = new SpringLayout();
    bigPanel = new JPanel(layout);
    //    bigPanel.setOpaque( false ) ;

    bigPanel.add(label);
    bigPanel.add(textField);

    // Adjust constraints for the label so it's at (5,5).
    layout.putConstraint(SpringLayout.WEST, label, 10, SpringLayout.WEST, bigPanel);
    layout.putConstraint(SpringLayout.NORTH, label, 6, SpringLayout.NORTH, bigPanel);

    // Adjust constraints for the text field so it's at
    // (<label's right edge> + 5, 5).
    layout.putConstraint(SpringLayout.WEST, textField, 10, SpringLayout.EAST, label);
    layout.putConstraint(SpringLayout.NORTH, textField, -2, SpringLayout.NORTH, label);

    // Adjust constraints for the content pane: Its right
    // edge should be 5 pixels beyond the text field's right
    // edge, and its bottom edge should be 5 pixels beyond
    // the bottom edge of the tallest component (which we'll
    // assume is textField).
    layout.putConstraint(SpringLayout.EAST, bigPanel, 5, SpringLayout.EAST, textField);
    layout.putConstraint(
        SpringLayout.SOUTH,
        bigPanel,
        //                          8,
        //                          SpringLayout.SOUTH, label ) ;
        5,
        SpringLayout.SOUTH,
        textField);

    // build image section ----------------------------------------------------
    imageLabel = new JLabel();
    imageLabel.setOpaque(false);
    fieldState = REQUIRE_STATE;
    setImage();
    textField.other = imageLabel;

    // insert image and labeled-field -----------------------------------------
    this.add(imageLabel);
    this.add(bigPanel);

    // pipe all focus events to local class methods
    super.addFocusListener(this);
  }