java swing中按钮的颜色要怎么设置

java swing中按钮的颜色要怎么设置,第1张

1.1 olor

1.1.1 new Color(red, green,blue)

red, green,blue: 0~255

swing基础概念教程:

这是一个简单的Swingd窗带有Yes/No 按钮,还有一个默认的关闭按钮,

下面的通过代码来简单介绍下d窗的使用,

import javax.swing.JOptionPane

public class Demo {

public static void main(String[] args) {

int choose = JOptionPane.showConfirmDialog(null, "5+5=10吗?", "提示", JOptionPane.YES_NO_OPTION) // 返回值为0或1

//由于该对话框可以获取返回值, 所以根据返回值的不同,进行不同的处理

if (choose == JOptionPane.YES_OPTION) {

System.out.println("你选择了Yes")

} else if (choose == JOptionPane.NO_OPTION) {

System.out.println("你选择了NO")

} else if (choose == JOptionPane.DEFAULT_OPTION) {

System.out.println("你直接关闭了对话框,没有做出选择!")

}

}

}

你可以将容器的整体布局设置为FlowLayout,然后在FlowLayout中添加一个Box布局,Box再添加3个部分,分别是表格、标签和按钮,两个按钮可以在用一个再新建一个Box对象并添加进去,下面是代码:

import javax.swing.*

import java.awt.*

public class test extends JFrame{

public test()

{

setSize(300,200)

setLocationRelativeTo(null) //使窗体居中显示

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

setLayout(new FlowLayout())

setTitle("用户信息")

String str[] = {"属性","信息"}

Object str2[][]={{"姓名",""},{"职工号",""},{"身份z号",""},{"性别",""},{"出生年月",""}}

JTable table = new JTable(str2,str)

JButton Button1 = new JButton("修改信息")

JButton Button2 = new JButton("修改密码")

JLabel Label = new JLabel("用户:",JLabel.CENTER)

JScrollPane scrollpane = new JScrollPane(table)

Box box = Box.createVerticalBox()

Box buttonBox = Box.createHorizontalBox()

buttonBox.add(Button1)

buttonBox.add(Button2)

box.add(table)

box.add(Label)

box.add(buttonBox)

add(box)

}

public static void main(String []args)

{

test Test = new test()

Test.setVisible(true)

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/7842099.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存