Ⅰ java 设置窗口背景图片还有设置按钮的字体格式例如大小等等··
要加背景的话,可以先声明一个背景JPanel,在这个JPanel上面画上图片,可以像这样做
JPanel panel = new JPanel() {
@Override
protected void printComponent(Graphics arg0) {
// TODO Auto-generated method stub
super.printComponent(arg0);
arg0.drawImage(img, x, y, width, height, observer);
}
};
你也可以自己继承JPanel类,然后把图片、大小作为参数传递,然后构造这样的JPanel。
然后把你放在frame上的东西都放在这个JPanel上。
设置字体你的方法是正确的.setFont(new Font("微软雅黑", Font.LAYOUT_NO_LIMIT_CONTEXT, 14));,如果想要都设置字体好像只能对每个组件都设置。
Ⅱ java中如何设置按钮文字的大小、颜色和字体
submit= new JButton("登陆");
submit.setFont(new Font("宋体", Font.PLAIN, 16));
三个参数分别表示: 字体,样式(粗体,斜体等),字号
submit.setForeground(Color.RED);
这个表示给组件上的文字设置颜色Color.RED表示红色
当然你也可以自己给RGB的值 比如 submit.setForeground(new Color(215,215,200));
JLabel组件支持HTML标记代码
infoLab= new JLabel("<html><a href='地址'>用户登陆系统</a></html>", JLabel.CENTER);
*注意:地址要单引号引起来。这个表示给用户登录系统几个字增加超链接
infoLab .setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
这个表示给这个文字添加鼠标样式,当鼠标移动到文字上,鼠标变成手型
Ⅲ 安卓Java怎么设置Button的字体
使用方法
第一种是在listview中配置android:listSelector=”@drawable/list_item_bg”
第二种是在listview的item中添加属性android:background=”@drawable/list_item_bg”
第三种是java代码中使用:
Drawable drawable = getResources().getDrawable(R.drawable.list_item_bg);
listview.setSelector(drawable);
注:列表有时候为黑的情况,需要加上下面的代码使其透明:
android:cacheColorHint="@android:color/transparent"
使用selector设置字体颜色
1
2
3
4
5
6
7
8
drawable/button_font.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="<a href="http://schemas.android.com/apk/res/android">" target="_blank">http://schemas.android.com/apk/res/android"></a>
<item android:state_selected="true" android:color="#FF0000" />
<item android:state_focused="true" android:color="#00FF00" />
<item android:state_pressed="true" android:color="#0000FF" />
<item android:color="#000000" />
</selector>
Ⅳ java中,怎么设置JButton字体的大小和粗体
可以这样设置JButton的字体大小和粗体
JButton jb=new JButton("确定");
Font f=new Font("宋体",Font.BOLD,16);//根据指定字体名称、样式和磅值大小,创建一个新 Font。
jb.setFont(f);
Ⅳ 怎样改变java中按钮的字体和颜色
submit= new JButton("登陆");
submit.setFont(new Font("宋体", Font.PLAIN, 16));
三个参数分别表示: 字体,样式(粗体,斜体等),字号
submit.setForeground(Color.RED);
这个表示给组件上的文字设置颜色Color.RED表示红色
当然你也可以自己给RGB的值 比如 submit.setForeground(new Color(215,215,200));
JLabel组件支持HTML标记代码
infoLab= new JLabel("<html><a href='地址'>用户登陆系统</a></html>", JLabel.CENTER);
*注意:地址要单引号引起来。这个表示给用户登录系统几个字增加超链接
infoLab .setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
这个表示给这个文字添加鼠标样式,当鼠标移动到文字上,鼠标变成手型
Ⅵ java通过按钮改变文本框内字体颜色,在原代码上面改,尽量简单一点
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.border.EmptyBorder;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;
public class main {
static String tf_str=null;
public static void main(String[] args) {
Frame a = new Frame("打印");
a.setBounds(400, 300, 400, 300);
a.setLayout(new FlowLayout());
TextField b = new TextField(20);
Button c = new Button("确定");
Button e = new Button("红色");
Button f = new Button("蓝色");
JTextPane d=new JTextPane();
d.setMargin(new Insets(100,100, 100, 100));
a.add(b);
a.add(c);
a.add(d);
a.add(e);
a.add(f);
a.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
c.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
d.setText("");
tf_str = b.getText().trim();
b.setText("");
appendToPane(d, tf_str, Color.black);
b.requestFocus();
}
});
e.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
d.setText("");
appendToPane(d, tf_str, Color.RED);
}
});
f.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
d.setText("");
appendToPane(d, tf_str, Color.BLUE);
}
});
a.setVisible(true);
}
private static void appendToPane(JTextPane tp, String msg, Color c) {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
aset = sc.addAttribute(aset, StyleConstants.FontFamily, "宋体");
aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
int len = tp.getDocument().getLength();
tp.setCaretPosition(len);
tp.setCharacterAttributes(aset, false);
tp.replaceSelection(msg);
}
}
Ⅶ java 按钮字体设置问题
pack() 函数可以自动调整按钮的尺寸来适合文字。
Button btnDemo = new Button("This is a demo");
....... // 你的代码
btnDemo.pack();
.......