下面列出了javax.swing.JComponent#repaint ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* highlights given component by altering its border's attributes
*/
protected void setHighlight(JComponent comp,boolean isToBeHighlighted) {
//quit if nothing is to be done
if (isToBeHighlighted && highlightedComps.contains(comp)) return;
if (!isToBeHighlighted && !highlightedComps.contains(comp)) return;
if (comp.getBorder() instanceof FieldBorder) {
FieldBorder fb = (FieldBorder)comp.getBorder();
fb.setHighlight(isToBeHighlighted);
comp.repaint();
if (isToBeHighlighted) {
highlightedComps.add(comp);
} else {
highlightedComps.remove(comp);
}
}
}
private static void checkVisibility(JComponent comp) {
if (comp == null) return;
comp.invalidate();
comp.revalidate();
comp.doLayout();
comp.repaint();
for (Component c : comp.getComponents())
if (c.isVisible()) {
comp.setVisible(true);
return;
}
comp.setVisible(false);
}
void repaintComponents()
{
synchronized (components) {
for (final JComponent comp : components) {
comp.invalidate();
comp.repaint();
}
}
}
protected void removeAllHighlights() {
for (JComponent c : highlightedComps) {
if (c.getBorder() instanceof FieldBorder) {
FieldBorder fb = (FieldBorder)c.getBorder();
fb.setHighlight(false);
c.repaint();
}
}
highlightedComps.clear();
}
void repaintComponents()
{
synchronized (components) {
for (final JComponent comp : components) {
comp.invalidate();
comp.repaint();
}
}
}
private void removeFeature() {
JComponent parent = (JComponent) getParent();
parent.remove(this);
if (parent.getComponentCount() == 0) {
parent.add(new NoFeature(mRow));
}
parent.revalidate();
parent.repaint();
}
private void refreshMenu() {
if (menuItems != null && menuItems.length > 0) {
firstIndex = Math.max(topFixedCount, firstIndex);
firstIndex = Math.min(menuItems.length - bottomFixedCount - scrollCount, firstIndex);
upItem.setEnabled(firstIndex > topFixedCount);
downItem.setEnabled(firstIndex + scrollCount < menuItems.length - bottomFixedCount);
menu.removeAll();
for (int i = 0; i < topFixedCount; i++) {
menu.add(menuItems[i]);
}
if (topFixedCount > 0) {
menu.add(new JSeparator());
}
menu.add(upItem);
for (int i = firstIndex; i < scrollCount + firstIndex; i++) {
menu.add(menuItems[i]);
}
menu.add(downItem);
if (bottomFixedCount > 0) {
menu.add(new JSeparator());
}
for (int i = menuItems.length - bottomFixedCount; i < menuItems.length; i++) {
menu.add(menuItems[i]);
}
JComponent parent = (JComponent) upItem.getParent();
parent.revalidate();
parent.repaint();
}
}
private void addDefault() {
SkillDefault skillDefault = new SkillDefault(LAST_ITEM_TYPE, LAST_ITEM_TYPE.isSkillBased() ? "" : null, null, 0); //$NON-NLS-1$
JComponent parent = (JComponent) getParent();
parent.add(new SkillDefaultEditor(skillDefault));
if (mDefault == null) {
parent.remove(this);
}
parent.revalidate();
parent.repaint();
notifyActionListeners();
}
@Override
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
if (CHANGE_BASE_TYPE.equals(command)) {
Class<?> type = BASE_TYPES[mBaseTypeCombo.getSelectedIndex()];
if (!mPrereq.getClass().equals(type)) {
JComponent parent = (JComponent) getParent();
PrereqList list = mPrereq.getParent();
int listIndex = list.getIndexOf(mPrereq);
try {
Prereq prereq;
if (type == ContainedWeightPrereq.class) {
prereq = new ContainedWeightPrereq(list, mRow.getDataFile().defaultWeightUnits());
} else {
prereq = (Prereq) type.getConstructor(PrereqList.class).newInstance(list);
}
if (prereq instanceof HasPrereq && mPrereq instanceof HasPrereq) {
((HasPrereq) prereq).has(((HasPrereq) mPrereq).has());
}
list.add(listIndex, prereq);
list.remove(mPrereq);
parent.add(create(mRow, prereq, mDepth), UIUtilities.getIndexOf(parent, this));
} catch (Exception exception) {
// Shouldn't have a failure...
exception.printStackTrace(System.err);
}
parent.remove(this);
parent.revalidate();
parent.repaint();
ListPrereqEditor.setLastItemType(type);
}
} else if (CHANGE_HAS.equals(command)) {
((HasPrereq) mPrereq).has(((JComboBox<?>) event.getSource()).getSelectedIndex() == 0);
} else {
super.actionPerformed(event);
}
}
public static void setZoomingEnabled(JComponent chartUI, boolean enabled) {
SimpleXYChart chart = (SimpleXYChart)chartUI.getClientProperty("chart"); // NOI18N
if (chart.isZoomingEnabled() == enabled) return;
else chart.setZoomingEnabled(enabled);
JPanel sidePanel = (JPanel)chartUI.getClientProperty("sidePanel"); // NOI18N
JPanel scrollerPanel = (JPanel)chartUI.getClientProperty("scrollerPanel"); // NOI18N
if (enabled) {
TransparentToolBar toolbar = new TransparentToolBar(false);
for (Action action : chart.getActions()) toolbar.addItem(action);
sidePanel.add(toolbar);
JScrollBar scroller = chart.getScroller();
scroller.setSize(scroller.getPreferredSize());
scrollerPanel.add(scroller);
chart.putClientProperty("scroller", scroller); // NOI18N
} else {
sidePanel.removeAll();
scrollerPanel.removeAll();
chart.putClientProperty("scroller", null); // NOI18N
}
sidePanel.setVisible(enabled);
chartUI.doLayout();
chartUI.repaint();
}
public void updateScroll()
{
List<JMenuItem> menuKeyList = getKeyList();
// Keep the first index less than the total number available in the list (unfiltered) minus the length of the scroll count, and no lower than zero
firstIndex = Math.min(firstIndex, menuKeyList.size() - SCROLL_COUNT);
firstIndex = Math.max(firstIndex, 0);
int lastIndex = firstIndex + Math.min(menuKeyList.size(), SCROLL_COUNT);
int runningUnfilteredCount = 0;
for (int i = 0; i < menuKeyList.size(); i++)
{
JMenuItem jmi = menuKeyList.get(i);
MenuVisibilityStatus status = allMenuItems.get(jmi);
final boolean inScrollBounds = !status.isFiltered() && runningUnfilteredCount >= firstIndex && runningUnfilteredCount < lastIndex;
status.setOutOfScrollBounds(!inScrollBounds);
if (!status.isFiltered())
{
runningUnfilteredCount++;
}
}
mainMenu.getPopupMenu().removeAll();
setMenuItemFilterVisibility();
upItem.setEnabled(firstIndex > 0);
mainMenu.getPopupMenu().add(upItem);
List<JMenuItem> inBoundsScrollMenuFolders = getInBoundScrollMenuFolders();
for (JMenuItem menuFolder : inBoundsScrollMenuFolders)
{
mainMenu.getPopupMenu().add(menuFolder);
}
downItem.setEnabled(lastIndex < runningUnfilteredCount);
mainMenu.getPopupMenu().add(downItem);
JComponent parent = (JComponent) upItem.getParent();
parent.revalidate();
parent.repaint();
}
void repaintComponents()
{
for (final JComponent comp : components) {
comp.invalidate();
comp.repaint();
}
}
protected void layoutContainerImmediately(JComponent parent) {
synchronized (parent.getTreeLock()) {
Map<JComponent, Rectangle> destMap = getDestinationMap(parent);
for (Entry<JComponent, Rectangle> entry : destMap.entrySet()) {
entry.getKey().setBounds(entry.getValue());
}
}
parent.repaint();
}
/**
*
*/
public void updateGui() {
graphPanelObject.invalidateCache();
JComponent selectedTab = (JComponent) getSelectedComponent();
selectedTab.updateUI();
selectedTab.repaint();
}
public void repaint() {
JComponent jc = getContainerResolve();
if (jc != null)
jc.repaint(getBorderBounds());
if (hostedComponent != null)
hostedComponent.repaint();
}
public static void repaint(JComponent component, Rectangle2D r) {
component.repaint((int)r.getX(), (int)r.getY(), (int)r.getWidth(), (int)r.getHeight());
}
/**
* Do only call this method if you are sure that a complete repaint is
* needed!
*/
public synchronized void repaintAll(Rectangle r) {
for (JComponent l : layers) {
l.repaint(r);
}
}
public void mouseClicked(MouseEvent e) {
JComponent c = (JComponent) e.getComponent();
c.repaint();
}
public void repaintCell(int px, int py) {
JComponent jc = getContainerResolve();
if (jc != null)
jc.repaint(getCellBorderBounds(px, py));
}
/**
* Repaint all panels using this UI.
*/
protected void repaintInstalledPanels() {
for (JComponent jc : getInstalledPanels()) {
jc.repaint();
}
}