public void paint(Graphics g) { imageLabel.setLocation(textField.getX() - 8, 2); super.paint(g); // System.out.println( "panel paint" ) ; }
/** 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); }
// icon handling ------------------------------------------------------------ // setzt anhand des Status (fieldState) das entsprechende Icon private final void setImage() { switch (fieldState) { case ERROR_STATE: currentImage = errorIcon.getImage(); imageLabel.setIcon(errorIcon); imageLabel.setToolTipText("failure"); textField.setMargin(bildInsets); break; case REQUIRE_STATE: currentImage = requireIcon.getImage(); imageLabel.setIcon(requireIcon); imageLabel.setToolTipText("required"); textField.setMargin(bildInsets); break; case WARNING_STATE: currentImage = warningIcon.getImage(); imageLabel.setIcon(warningIcon); imageLabel.setToolTipText("warning"); textField.setMargin(bildInsets); break; case CHECKED_STATE: currentImage = checkedIcon.getImage(); imageLabel.setIcon(checkedIcon); imageLabel.setToolTipText("ok"); textField.setMargin(bildInsets); break; case USER_STATE: currentImage = userIcon.getImage(); imageLabel.setIcon(userIcon); imageLabel.setToolTipText("user message"); textField.setMargin(bildInsets); break; default: // case NOTHING_STATE : currentImage = null; imageLabel.setIcon(null); imageLabel.setToolTipText(""); textField.setMargin(leerInsets); } repaint(); }
public String getLabelText() { return label.getText(); }
// -------------------------------------------------------------------------- public void setLabelText(String labelText) { label.setText(labelText); }