java 公共组件_【JAVA语言程序设计基础篇】--Swing GUI组件的公共特性
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.LineBorder;//線框
import javax.swing.border.TitledBorder;//標(biāo)題框
@SuppressWarnings("serial")
public class TestSwingCommonFeatures extends JFrame{
public TestSwingCommonFeatures(){
JPanel p1 = new JPanel (new FlowLayout(FlowLayout.LEFT,2,2));
JButton jbtleft = new JButton("left");
JButton jbtcenter = new JButton("CENTER");
JButton jbtright = new JButton("right");
jbtleft.setBackground(Color.white);
jbtcenter.setForeground(Color.green);
jbtright.setToolTipText("this is the right button");
p1.add(jbtleft);
p1.add(jbtcenter);
p1.add(jbtright);
p1.setBorder(new TitledBorder("three buttons"));
//-------------------------------------//
Font largeFont =new Font ("TimesRoman",Font.BOLD,20);//字體
JPanel p2 = new JPanel (new FlowLayout(FlowLayout.LEFT,5,5));
JButton jbtred = new JButton ("red");
JButton jbtorange = new JButton("orange");
jbtred.setFont(largeFont);
jbtred.setBackground(Color.red);
jbtorange.setForeground(Color.orange);
jbtorange.setToolTipText("this is a orange button");
p2.add(jbtred);
p2.add(jbtorange);
p2.setBorder(new LineBorder(Color.green,4));//被下一行覆蓋
p2.setBorder(new TitledBorder("a"));
p2.setLayout(new GridLayout(1,2,1,10));
setLayout(new FlowLayout(FlowLayout.LEFT,30,30));
setLayout(new GridLayout(1,2,5,10));//下一行有一個新的setlayout 這一樣的setlayout被覆蓋,就不顯示了
add(p1);
add(p2);
}
public static void main(String[] args) {
JFrame frame = new TestSwingCommonFeatures();
frame.setTitle("test swing common features");
frame.setSize(500, 150);
frame.setLocationRelativeTo(null);//放中間
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
展示
Font 字體
Color 顏色
Border 框
原文:http://blog.csdn.net/qq_24653023/article/details/52102692
總結(jié)
以上是生活随笔為你收集整理的java 公共组件_【JAVA语言程序设计基础篇】--Swing GUI组件的公共特性的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java json自定义_java返回j
- 下一篇: java策略模式 if else_Jav