Di sini adalah cara untuk mempercantik Textfield , di Textfield tidak seperti di JButton yang memiliki model . tapi kita masih dapat memanipulasi tampilan Textfiled . contohnya seperti di bawah ini :
import
java.awt.Color;
import
java.awt.GradientPaint;
import
java.awt.Graphics;
import
java.awt.Graphics2D;
import
java.awt.RenderingHints;
import
javax.swing.JTextField;
import
javax.swing.border.EmptyBorder;
public
class
TextFieldMakeOver
extends
JTextField {
public
TextFieldMakeOver() {
setOpaque(
false
);
setForeground(Color.WHITE);
setCaretColor(Color.WHITE);
setBorder(
new
EmptyBorder(
6
,
6
,
6
,
6
));
}
@Override
protected
void
paintComponent(Graphics g) {
super
.paintComponent(g);
Graphics2D gd = (Graphics2D) g.create();
gd.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gd.setPaint(
new
GradientPaint(
0
,
0
,
new
Color(
255
,
255
,
255
,
120
),
0
, getHeight(),
new
Color(
0
,
0
,
0
,
0
)));
gd.fillRoundRect(
0
,
0
, getWidth(), getHeight(),
25
,
25
);
gd.setColor(Color.white);
gd.drawRoundRect(
0
,
0
, getWidth()
1
, getHeight()
1
,
25
,
25
);
gd.dispose();
}
}
private
ButtonMakeOver button =
new
ButtonMakeOver(
"My Button"
);
Menjadi :
private
TextFieldMakeOver textField =
new
TextFieldMakeOver();
0 komentar:
Posting Komentar