Java Code Examples for java.awt.Component#hasFocus()
The following examples show how to use
java.awt.Component#hasFocus() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: xyTalk-pc File: GraphicUtils.java License: GNU Affero General Public License v3.0 | 6 votes |
/** * @param c * Component to check on. * @return returns true if the component of one of its child has the focus */ public static boolean isAncestorOfFocusedComponent(Component c) { if (c.hasFocus()) { return true; } else { if (c instanceof Container) { Container cont = (Container) c; int n = cont.getComponentCount(); for (int i = 0; i < n; i++) { Component child = cont.getComponent(i); if (isAncestorOfFocusedComponent(child)) return true; } } } return false; }
Example 2
Source Project: PyramidShader File: FocusedBorder.java License: GNU General Public License v3.0 | 6 votes |
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Insets insets = getBorderInsets(c); if(c.hasFocus()) { Rectangle rect = new Rectangle(x+insets.left, y+insets.top, width-insets.left-insets.right-1, height-insets.top-insets.bottom-1); Graphics2D g2 = (Graphics2D)g.create(); GeneralPath focusOnly = new GeneralPath(Path2D.WIND_EVEN_ODD); focusOnly.append(new Rectangle(x,y,width,height), false); focusOnly.append(new Rectangle(x+insets.left,y+insets.top, width-insets.left-insets.right, height-insets.top-insets.bottom), false); g2.clip(focusOnly); PlafPaintUtils.paintFocus(g2, rect, 3); } else if(unfocusedBorder!=null) { Insets borderInsets = unfocusedBorder.getBorderInsets(c); unfocusedBorder.paintBorder(c, g, x+insets.left-borderInsets.left, y+insets.top-borderInsets.top, width-insets.left-insets.right+borderInsets.left+borderInsets.right, height-insets.top-insets.bottom+borderInsets.top+borderInsets.bottom); } }
Example 3
Source Project: Spark File: GraphicUtils.java License: Apache License 2.0 | 6 votes |
/** * @param c * Component to check on. * @return returns true if the component of one of its child has the focus */ public static boolean isAncestorOfFocusedComponent(Component c) { if (c.hasFocus()) { return true; } else { if (c instanceof Container) { Container cont = (Container) c; int n = cont.getComponentCount(); for (int i = 0; i < n; i++) { Component child = cont.getComponent(i); if (isAncestorOfFocusedComponent(child)) return true; } } } return false; }
Example 4
Source Project: jdk1.8-source-analysis File: MotifBorders.java License: Apache License 2.0 | 5 votes |
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { if (c.hasFocus()) { g.setColor(focus); g.drawRect(x, y, w-1, h-1); } else { g.setColor(control); g.drawRect(x, y, w-1, h-1); } }
Example 5
Source Project: dragonwell8_jdk File: MotifBorders.java License: GNU General Public License v2.0 | 5 votes |
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { if (c.hasFocus()) { g.setColor(focus); g.drawRect(x, y, w-1, h-1); } else { g.setColor(control); g.drawRect(x, y, w-1, h-1); } }
Example 6
Source Project: jdk8u-jdk File: TranserFocusToWindow.java License: GNU General Public License v2.0 | 5 votes |
private static void setFocus(final Component comp, final Robot r) { if (comp.hasFocus()) { return; } Util.clickOnComp(comp, r); Util.waitForIdle(r); if (!comp.hasFocus()) { throw new RuntimeException("can not set focus on " + comp); } }
Example 7
Source Project: openjdk-8 File: MotifBorders.java License: GNU General Public License v2.0 | 5 votes |
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { if (c.hasFocus()) { g.setColor(focus); g.drawRect(x, y, w-1, h-1); } else { g.setColor(control); g.drawRect(x, y, w-1, h-1); } }
Example 8
Source Project: TencentKona-8 File: TranserFocusToWindow.java License: GNU General Public License v2.0 | 5 votes |
private static void setFocus(final Component comp, final Robot r) { if (comp.hasFocus()) { return; } Util.clickOnComp(comp, r); Util.waitForIdle(r); if (!comp.hasFocus()) { throw new RuntimeException("can not set focus on " + comp); } }
Example 9
Source Project: jdk8u60 File: MotifBorders.java License: GNU General Public License v2.0 | 5 votes |
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { if (c.hasFocus()) { g.setColor(focus); g.drawRect(x, y, w-1, h-1); } else { g.setColor(control); g.drawRect(x, y, w-1, h-1); } }
Example 10
Source Project: jdk8u60 File: TranserFocusToWindow.java License: GNU General Public License v2.0 | 5 votes |
private static void setFocus(final Component comp, final Robot r) { if (comp.hasFocus()) { return; } Util.clickOnComp(comp, r); Util.waitForIdle(r); if (!comp.hasFocus()) { throw new RuntimeException("can not set focus on " + comp); } }
Example 11
Source Project: JDKSourceCode1.8 File: MotifBorders.java License: MIT License | 5 votes |
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { if (c.hasFocus()) { g.setColor(focus); g.drawRect(x, y, w-1, h-1); } else { g.setColor(control); g.drawRect(x, y, w-1, h-1); } }
Example 12
Source Project: hottub File: TranserFocusToWindow.java License: GNU General Public License v2.0 | 5 votes |
private static void setFocus(final Component comp, final Robot r) { if (comp.hasFocus()) { return; } Util.clickOnComp(comp, r); Util.waitForIdle(r); if (!comp.hasFocus()) { throw new RuntimeException("can not set focus on " + comp); } }
Example 13
Source Project: openjdk-8-source File: TranserFocusToWindow.java License: GNU General Public License v2.0 | 5 votes |
private static void setFocus(final Component comp, final Robot r) { if (comp.hasFocus()) { return; } Util.clickOnComp(comp, r); Util.waitForIdle(r); if (!comp.hasFocus()) { throw new RuntimeException("can not set focus on " + comp); } }
Example 14
Source Project: javamoney-examples File: PopupMenu.java License: Apache License 2.0 | 5 votes |
/** * This method is invoked when the specific mouse event occurs. * * @param event The mouse event that occurred. */ public void mouseReleased(MouseEvent event) { Component component = event.getComponent(); if(component.hasFocus() == false) { component.requestFocus(); } if(component.isEnabled() == true) { if(behaveLikeMenu() == true) { if(event.getButton() == BUTTON1) { show(component, 0, component.getHeight()); } } else if(event.isPopupTrigger() == true) { int yCoordinate = 0; if(allowFloatingY() == true) { yCoordinate = event.getY(); } show(component, event.getX(), yCoordinate); } } }
Example 15
Source Project: openjdk-8 File: TranserFocusToWindow.java License: GNU General Public License v2.0 | 5 votes |
private static void setFocus(final Component comp, final Robot r) { if (comp.hasFocus()) { return; } Util.clickOnComp(comp, r); Util.waitForIdle(r); if (!comp.hasFocus()) { throw new RuntimeException("can not set focus on " + comp); } }
Example 16
Source Project: Bytecoder File: MotifBorders.java License: Apache License 2.0 | 5 votes |
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { if (c.hasFocus()) { g.setColor(focus); g.drawRect(x, y, w-1, h-1); } else { g.setColor(control); g.drawRect(x, y, w-1, h-1); } }
Example 17
Source Project: openjdk-jdk9 File: TranserFocusToWindow.java License: GNU General Public License v2.0 | 5 votes |
private static void setFocus(final Component comp, final Robot r) { if (comp.hasFocus()) { return; } Util.clickOnComp(comp, r); Util.waitForIdle(r); if (!comp.hasFocus()) { throw new RuntimeException("can not set focus on " + comp); } }
Example 18
Source Project: jdk8u-jdk File: MotifBorders.java License: GNU General Public License v2.0 | 5 votes |
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { if (c.hasFocus()) { g.setColor(focus); g.drawRect(x, y, w-1, h-1); } else { g.setColor(control); g.drawRect(x, y, w-1, h-1); } }
Example 19
Source Project: jdk8u-jdk File: TranserFocusToWindow.java License: GNU General Public License v2.0 | 5 votes |
private static void setFocus(final Component comp, final Robot r) { if (comp.hasFocus()) { return; } Util.clickOnComp(comp, r); Util.waitForIdle(r); if (!comp.hasFocus()) { throw new RuntimeException("can not set focus on " + comp); } }
Example 20
Source Project: whyline File: WhylineControlBorder.java License: MIT License | 4 votes |
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { if(!c.isVisible()) return; Graphics2D g2 = (Graphics2D)g.create(); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); Stroke old = g2.getStroke(); g2.setStroke(new BasicStroke(UI.getBorderPadding())); g2.setColor(UI.getPanelLightColor()); g2.drawRect(0, 0, width, height); int corner = UI.getRoundedness() - 1; int widthOfControlBackgroundStroke = UI.getBorderPadding() + 1; g2.setStroke(new BasicStroke(widthOfControlBackgroundStroke)); g2.setColor(c.getBackground()); g2.drawRoundRect( widthOfControlBackgroundStroke / 2 - 1, widthOfControlBackgroundStroke / 2 - 1, width - widthOfControlBackgroundStroke + 1, height - widthOfControlBackgroundStroke + 1, corner, corner); g2.setStroke(old); if(c.hasFocus()) { g2.setColor(UI.getFocusColor()); float strokeWidth = 2.0f; g2.setStroke(new BasicStroke(strokeWidth)); g2.drawRect((int)(strokeWidth / 2), (int)(strokeWidth / 2), (int)(width - strokeWidth - 1), (int)(height - strokeWidth - 1)); } else { g2.setColor(c.isEnabled() ? UI.getControlBorderColor() : UI.getControlBorderColor().darker()); g2.drawRoundRect(0, 0, width - 1, height - 1, corner, corner); } }