javax.swing.JComponent#hasFocus ( )源码实例Demo

下面列出了javax.swing.JComponent#hasFocus ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: rapidminer-studio   文件: ListPropertyTable2.java
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;
}
 
源代码2 项目: PyramidShader   文件: MultiThumbSliderUI.java
@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);
}
 
源代码3 项目: pumpernickel   文件: MultiThumbSliderUI.java
@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);
}
 
源代码4 项目: seaglass   文件: SeaGlassTextFieldUI.java
/**
 * 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);
    }
}
 
源代码5 项目: Bytecoder   文件: SwingUtilities2.java
/**
 * 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();
    }
}
 
源代码6 项目: pumpernickel   文件: InspectorLayout.java
@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();
	}
}