本文整理匯總了Java中javax.swing.JTextPane.paint方法的典型用法代碼示例。如果您正苦於以下問題:Java JTextPane.paint方法的具體用法?Java JTextPane.paint怎麽用?Java JTextPane.paint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JTextPane
的用法示例。
在下文中一共展示了JTextPane.paint方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: draw
import javax.swing.JTextPane; //導入方法依賴的package包/類
public void draw(Graphics g, GamePieceImage defn) {
TextBoxItemInstance tbi = null;
if (defn != null) {
tbi = defn.getTextBoxInstance(getConfigureName());
}
if (tbi == null) {
tbi = new TextBoxItemInstance();
}
Color fg = tbi.getFgColor().getColor();
Color bg = tbi.getBgColor().getColor();
Point origin = layout.getPosition(this);
Rectangle r = new Rectangle(origin.x, origin.y, getWidth(), getHeight());
String s = null;
if (textSource.equals(SRC_FIXED)) {
s = text;
}
else {
if (defn != null) {
if (tbi != null) {
s = tbi.getValue();
}
}
}
Graphics2D g2d = ((Graphics2D) g);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, isAntialias() ?
RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
AffineTransform saveXForm = null;
if (getRotation() != 0) {
saveXForm = g2d.getTransform();
AffineTransform newXForm =
AffineTransform.getRotateInstance(Math.toRadians(getRotation()), getLayout().getVisualizerWidth()/2, getLayout().getVisualizerHeight()/2);
g2d.transform(newXForm);
}
if (bg != null) {
g.setColor(bg);
g.fillRect(r.x, r.y, r.width, r.height);
}
JTextPane l = new JTextPane();
if (isHTML) l.setContentType("text/html"); //$NON-NLS-1$
l.setText(s);
l.setSize(width-2, height-2);
l.setBackground(bg != null ? bg : new Color(0,true));
l.setForeground(fg != null ? fg : new Color(0,true));
FontStyle fs = FontManager.getFontManager().getFontStyle(fontStyleName);
Font f = fs.getFont();
l.setFont(f);
final BufferedImage img = ImageUtils.createCompatibleTranslucentImage(
Math.max(l.getWidth(), 1),
Math.max(l.getHeight(), 1)
);
final Graphics2D big = img.createGraphics();
l.paint(big);
big.dispose();
g2d.drawImage(img, origin.x+1, origin.y+1, null);
if (saveXForm != null) {
g2d.setTransform(saveXForm);
}
}