Java Code Examples for javax.swing.JComponent#hasFocus()
The following examples show how to use
javax.swing.JComponent#hasFocus() .
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 File: ListPropertyTable2.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
private boolean startCellEditingAndRequestFocus(int row, int column) { if (isCellEditable(row, column)) { editCellAt(row, column); Component editorComponent = getEditorComponent(); if (editorComponent != null) { if (editorComponent instanceof JComponent) { JComponent jComponent = (JComponent) editorComponent; if (!jComponent.hasFocus()) { jComponent.requestFocusInWindow(); } return true; } } } return false; }
Example 2
Source File: MultiThumbSliderUI.java From PyramidShader with GNU General Public License v3.0 | 6 votes |
@Override public void paint(Graphics g, JComponent slider2) { if(slider2!=slider) throw new RuntimeException("only use this UI on the GradientSlider it was constructed with"); Graphics2D g2 = (Graphics2D)g; int w = slider.getWidth(); int h = slider.getHeight(); if(slider.isOpaque()) { g.setColor(slider.getBackground()); g.fillRect(0,0,w,h); } if(slider2.hasFocus()) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); paintFocus(g2); } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); paintTrack(g2); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); paintThumbs(g2); }
Example 3
Source File: MultiThumbSliderUI.java From pumpernickel with MIT License | 5 votes |
@Override public void paint(Graphics g, JComponent slider2) { if (slider2 != slider) throw new RuntimeException( "only use this UI on the GradientSlider it was constructed with"); Graphics2D g2 = (Graphics2D) g; int w = slider.getWidth(); int h = slider.getHeight(); if (slider.isOpaque()) { g.setColor(slider.getBackground()); g.fillRect(0, 0, w, h); } if (slider2.hasFocus()) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); paintFocus(g2); } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); paintTrack(g2); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); paintThumbs(g2); }
Example 4
Source File: SeaGlassTextFieldUI.java From seaglass with Apache License 2.0 | 5 votes |
/** * DOCUMENT ME! * * @param context DOCUMENT ME! * @param g DOCUMENT ME! * @param c DOCUMENT ME! */ void paintBackground(SeaGlassContext context, Graphics g, JComponent c) { context.getPainter().paintTextFieldBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); // If necessary, paint the placeholder text. if (placeholderText != null && ((JTextComponent) c).getText().length() == 0 && !c.hasFocus()) { paintPlaceholderText(context, g, c); } }
Example 5
Source File: SwingUtilities2.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Request focus on the given component if it doesn't already have it * and {@code isRequestFocusEnabled()} returns true. */ public static void adjustFocus(JComponent c) { if (!c.hasFocus() && c.isRequestFocusEnabled()) { c.requestFocus(); } }
Example 6
Source File: InspectorLayout.java From pumpernickel with MIT License | 4 votes |
@Override public void paint(Graphics g0, JComponent c) { Graphics2D g = (Graphics2D) g0; if (c.isOpaque()) { if (clickable && c instanceof AbstractButton && ((AbstractButton) c).getModel().isArmed()) { g.setPaint(new GradientPaint(new Point(0, 0), new Color( 230, 230, 230), new Point(0, c.getHeight()), new Color(180, 180, 180))); } else { g.setPaint(new GradientPaint(new Point(0, 0), Color.white, new Point(0, c.getHeight()), new Color(216, 216, 216))); } g.fillRect(0, 0, c.getWidth(), c.getHeight()); Rectangle border = new Rectangle(0, 0, c.getWidth() - 1, c.getHeight() - 1); if (!isHorizontalEdgePainted()) { border.x--; border.width += 2; } if (c.hasFocus()) { Shape rect = new RoundRectangle2D.Float(border.x, border.y, border.width, border.height, 8, 8); com.pump.plaf.PlafPaintUtils.paintFocus(g, rect, 2); } g.setColor(Color.gray); g.setStroke(new BasicStroke(1)); g.drawRect(border.x, border.y, border.width, border.height); } super.paint(g, c); if (clickable) { Graphics2D g2 = (Graphics2D) g.create(); Number angle = (Number) c.getClientProperty(ROTATION); if (angle != null) { g2.rotate(angle.doubleValue(), 15, c.getHeight() / 2); } triangleIcon.paintIcon(c, g2, 15 - triangleIcon.getIconWidth() / 2, c.getHeight() / 2 - triangleIcon.getIconHeight() / 2); g2.dispose(); } }