本文整理了Java中javax.swing.text.JTextComponent.getWidth()
方法的一些代码示例,展示了JTextComponent.getWidth()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextComponent.getWidth()
方法的具体详情如下:
包路径:javax.swing.text.JTextComponent
类名称:JTextComponent
方法名:getWidth
暂无
代码示例来源:origin: ron190/jsql-injection
default void drawPlaceholder(JTextComponent textComponent, Graphics g, String placeholderText) {
int w = textComponent.getWidth();
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
Insets ins = textComponent.getInsets();
FontMetrics fm = g.getFontMetrics();
int c0 = textComponent.getBackground().getRGB();
int c1 = textComponent.getForeground().getRGB();
int m = 0xfefefefe;
int c2 = ((c0 & m) >>> 1) + ((c1 & m) >>> 1);
g.setColor(new Color(c2, true));
g.setFont(textComponent.getFont().deriveFont(Font.ITALIC));
g.drawString(
placeholderText,
textComponent.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT
? w - (fm.stringWidth(placeholderText) + ins.left + 2)
: ins.left + 2,
fm.getAscent() + 2
);
}
代码示例来源:origin: ron190/jsql-injection
@Override
protected synchronized void damage(Rectangle r) {
if (r == null) {
return;
}
// give values to x,y,width,height (inherited from java.awt.Rectangle)
this.x = r.x;
this.y = r.y;
this.height = r.height;
// A value for width was probably set by paint(), which we leave alone.
// But the first call to damage() precedes the first call to paint(), so
// in this case we must be prepared to set a valid width, or else
// paint()
// will receive a bogus clip area and caret will not get drawn properly.
if (this.width <= 0) {
this.width = this.getComponent().getWidth();
}
//Calls getComponent().repaint(x, y, width, height) to erase
this.repaint();
// previous location of caret. Sometimes one call isn't enough.
this.repaint();
}
代码示例来源:origin: net.java.abeille/abeille
public void repaint(int startY, int height) {
if (height <= 0) {
return;
}
int width = Math.max(component.getWidth(), 0);
startY = Math.max(startY, 0);
component.repaint(0, startY, width, height);
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
public void repaint(int startY, int height) {
if (height <= 0) {
return;
}
int width = Math.max(component.getWidth(), 0);
startY = Math.max(startY, 0);
component.repaint(0, startY, width, height);
}
代码示例来源:origin: org.swinglabs.swingx/swingx-core
/**
* {@inheritDoc}
*/
@Override
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g.create();
try {
painter.paint(g2d, c, c.getWidth(), c.getHeight());
} finally {
g2d.dispose();
}
}
代码示例来源:origin: robo-code/robocode
@Override
public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) {
try {
Rectangle r = c.modelToView(c.getCaretPosition());
g.setColor(color);
g.fillRect(0, r.y, c.getWidth(), r.height);
} catch (BadLocationException ignore) {}
}
};
代码示例来源:origin: org.gephi/directory-chooser
public void showPopup(JTextComponent source, int x, int y) {
if(list.getModel().getSize() == 0) {
return;
}
setPreferredSize(new Dimension(source.getWidth(), source.getHeight() * 4));
show(source, x, y);
ensureSelection();
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-dlight-nativeexecution-nb
public void showPopup(JTextComponent source, int x, int y) {
setPreferredSize(new Dimension(source.getWidth(), source.getHeight() * 4));
show(source, x, y);
list.clearSelection();
}
代码示例来源:origin: net.sf.nimrod/nimrod-laf
protected void paintFocus( Graphics g) {
JTextComponent c = getComponent();
if ( c.isEnabled() && c.isEditable() && !canijo ) {
if ( focus ) {
NimRODUtils.paintFocus( g, 1,1, c.getWidth()-2, c.getHeight()-2, 4,4, 3, NimRODLookAndFeel.getFocusColor());
}
else if ( rollover ) {
NimRODUtils.paintFocus( g, 1,1, c.getWidth()-2, c.getHeight()-2, 4,4, 3, NimRODUtils.getColorAlfa( NimRODLookAndFeel.getFocusColor(), 150));
}
}
}
代码示例来源:origin: com.jtattoo/JTattoo
protected void paintBackground(Graphics g) {
g.setColor(getComponent().getBackground());
if (AbstractLookAndFeel.getTheme().doShowFocusFrame()) {
Boolean doShow = (Boolean) getComponent().getClientProperty("doShowFocusFrame");
if (doShow == null || doShow.booleanValue()) {
if (getComponent().hasFocus() && getComponent().isEditable()) {
g.setColor(AbstractLookAndFeel.getTheme().getFocusBackgroundColor());
}
}
}
g.fillRect(0, 0, getComponent().getWidth(), getComponent().getHeight());
}
代码示例来源:origin: com.jtattoo/JTattoo
protected void paintBackground(Graphics g) {
g.setColor(getComponent().getBackground());
if (AbstractLookAndFeel.getTheme().doShowFocusFrame()) {
if (getComponent().hasFocus() && getComponent().isEditable()) {
g.setColor(AbstractLookAndFeel.getTheme().getFocusBackgroundColor());
}
}
g.fillRect(0, 0, getComponent().getWidth(), getComponent().getHeight());
}
代码示例来源:origin: com.jtattoo/JTattoo
protected void paintBackground(Graphics g) {
g.setColor(getComponent().getBackground());
if (AbstractLookAndFeel.getTheme().doShowFocusFrame()) {
if (getComponent().hasFocus() && getComponent().isEditable()) {
g.setColor(AbstractLookAndFeel.getTheme().getFocusBackgroundColor());
}
}
g.fillRect(0, 0, getComponent().getWidth(), getComponent().getHeight());
}
代码示例来源:origin: com.jtattoo/JTattoo
protected void paintBackground(Graphics g) {
g.setColor(getComponent().getBackground());
if (AbstractLookAndFeel.getTheme().doShowFocusFrame()) {
if (getComponent().hasFocus() && getComponent().isEditable()) {
g.setColor(AbstractLookAndFeel.getTheme().getFocusBackgroundColor());
}
}
g.fillRect(0, 0, getComponent().getWidth(), getComponent().getHeight());
}
代码示例来源:origin: net.java.abeille/abeille
public Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias b1, Shape a) throws BadLocationException {
Rectangle r0 = (Rectangle) modelToView(p0, a, b0);
Rectangle r1 = (Rectangle) modelToView(p1, a, b1);
if (r0.y != r1.y) {
// If it spans lines, force it to be the width of the view.
r0.x = getComponent().getX();
r0.width = getComponent().getWidth();
}
r0.add(r1);
return r0;
}
代码示例来源:origin: com.haulmont.thirdparty/swingx-core
protected void paintPromptComponent(Graphics g, JTextComponent txt) {
JTextComponent lbl = getPromptComponent(txt);
SwingUtilities.paintComponent(g, lbl, txt, 0, 0, txt.getWidth(), txt.getHeight());
if (txt.getCaret() != null) {
txt.getCaret().paint(g);
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
public Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias b1,
Shape a) throws BadLocationException {
Rectangle r0 = (Rectangle)modelToView(p0, a, b0);
Rectangle r1 = (Rectangle)modelToView(p1, a, b1);
if (r0.y != r1.y) {
// If it spans lines, force it to be the width of the view.
r0.x = getComponent().getX();
r0.width = getComponent().getWidth();
}
r0.add(r1);
return r0;
}
代码示例来源:origin: org.swinglabs.swingx/swingx-all
protected void paintPromptComponent(Graphics g, JTextComponent txt) {
JTextComponent lbl = getPromptComponent(txt);
SwingUtilities.paintComponent(g, lbl, txt, 0, 0, txt.getWidth(), txt.getHeight());
if (txt.getCaret() != null) {
txt.getCaret().paint(g);
}
}
代码示例来源:origin: org.bidib.jbidib.swinglabs.swingx/swingx-core
protected void paintPromptComponent(Graphics g, JTextComponent txt) {
JTextComponent lbl = getPromptComponent(txt);
SwingUtilities.paintComponent(g, lbl, txt, 0, 0, txt.getWidth(), txt.getHeight());
if (txt.getCaret() != null) {
txt.getCaret().paint(g);
}
}
代码示例来源:origin: org.swinglabs.swingx/swingx-core
protected void paintPromptComponent(Graphics g, JTextComponent txt) {
JTextComponent lbl = getPromptComponent(txt);
SwingUtilities.paintComponent(g, lbl, txt, 0, 0, txt.getWidth(), txt.getHeight());
if (txt.getCaret() != null) {
txt.getCaret().paint(g);
}
}
代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw
@Override
public void paintBackground(Graphics g) {
JTextComponent c = getComponent();
if (c.getBorder() instanceof BackdropBorder) {
BackdropBorder bb = (BackdropBorder) c.getBorder();
bb.getBackdropBorder().paintBorder(c, g, 0, 0, c.getWidth(), c.getHeight());
} else {
super.paintBackground(g);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!