Java Reference
In-Depth Information
Example 10•29: AppletMenuBar.java (continued)
public void insertMenu(String label, PopupMenu menu, int index) {
if (index < 0) index += labels.size()+1; // Position to put it at
this.add(menu);
// Popup belongs to us
labels.insertElementAt(label, index);
// Remember the label
menus.insertElementAt(menu, index);
// Remember the menu
remeasure = true;
// Remeasure everything
invalidate();
// Container must relayout
}
/** Property accessor methods for margins property */
public Insets getMargins() { return (Insets) margins.clone(); }
public void setMargins(Insets margins) {
this.margins = margins;
remeasure = true;
invalidate();
}
/** Property accessor methods for spacing property */
public int getSpacing() { return spacing; }
public void setSpacing(int spacing) {
if (this.spacing != spacing) {
this.spacing = spacing;
remeasure = true;
invalidate();
}
}
/** Accessor methods for highlightColor property */
public Color getHighlightColor() {
if (highlightColor == null) return getForeground();
else return highlightColor;
}
public void setHighlightColor(Color c) {
if (highlightColor != c) {
highlightColor = c;
repaint();
}
}
/** We override the setFont() method so we can remeasure */
public void setFont(Font f) {
super.setFont(f);
remeasure = true;
invalidate();
}
/** Override these color property setter method so we can repaint */
public void setForeground(Color c) {
super.setForeground(c);
repaint();
}
public void setBackground(Color c) {
super.setBackground(c);
repaint();
}
/**
* This method is called to draw tell the component to redraw itself.
Search WWH ::




Custom Search