怎样设置JButton的大小,形状(只是要它凸起),位置,颜色? 大小 setSize()位置 setLocation()颜色 setBackground()和setForeground() 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import javax.swing.UIManager;try{ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}catch(Exception e){System.exit(1);}这样你的按钮就会凸起来 to Philip1314;这段代码要放在哪里? import java.io.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.plaf.metal.*;public class TestNetPaint{ public static int count=100; public static void main(String[] args)throws Exception { JFrame myframe=new MyFrame(); myframe.show(); }} class MyFrame extends JFrame { public MyFrame() { addWindowListener ( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); setSize(600,400); Container contentPane=getContentPane(); MyPanel testPanel=new MyPanel(); JButton myButton=new JButton("test"); myButton.setFocusPainted(false);//取消聚焦框 myButton.setForeground(Color.pink); myButton.setBackground(Color.blue); testPanel.add(myButton); contentPane.add(testPanel); try{ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); SwingUtilities.updateComponentTreeUI(this); }catch(Exception e){ System.exit(1); } } } class MyPanel extends JPanel { TestNetPaint netpaint=new TestNetPaint(); public MyPanel() { } public void paint(Graphics g) { super.paint(g); System.out.println("MyPanel is running"); } } /*说明:1,在Swing里面我感觉控件的大小,位置无所谓的,只要你布局做的对,原始窗口 大小合适就好。 2,myButton.setFocusPainted(false);//取消 按钮上的test外还有个不知所云的框 3,UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); SwingUtilities.updateComponentTreeUI(this); 这句不能少,否则没用 4, myButton.setForeground(Color.pink); myButton.setBackground(Color.blue); 改变颜色*/ JAVAC总是报错 java+jsp如何连接到打印机并打印jsp页面上读出的数据 关于JAVA异常继承的问题。。 多线程并发求解 问个2除以5的问题 实现一棵树 问一个关于使用JAVA中的动态代理实现数据库连接池的问题 新手:XML在编程中有什么用途? javaswing里取jPassword里的内容的问题。 哪有PLC的相关资料或书籍(印刷版,电子版都行)300分相送 linux 下的java开发工具 大家好啊,十一假过的好吗?帮帮我吧,用java做个东西该.....
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e){
System.exit(1);
}这样你的按钮就会凸起来
这段代码要放在哪里?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.plaf.metal.*;public class TestNetPaint
{
public static int count=100;
public static void main(String[] args)throws Exception
{
JFrame myframe=new MyFrame();
myframe.show();
}
}
class MyFrame extends JFrame
{
public MyFrame()
{
addWindowListener
(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
setSize(600,400);
Container contentPane=getContentPane();
MyPanel testPanel=new MyPanel();
JButton myButton=new JButton("test");
myButton.setFocusPainted(false);//取消聚焦框
myButton.setForeground(Color.pink);
myButton.setBackground(Color.blue);
testPanel.add(myButton);
contentPane.add(testPanel);
try{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.updateComponentTreeUI(this);
}catch(Exception e){
System.exit(1);
}
}
}
class MyPanel extends JPanel
{
TestNetPaint netpaint=new TestNetPaint();
public MyPanel()
{
}
public void paint(Graphics g)
{
super.paint(g);
System.out.println("MyPanel is running");
}
} /*说明:1,在Swing里面我感觉控件的大小,位置无所谓的,只要你布局做的对,原始窗口
大小合适就好。
2,myButton.setFocusPainted(false);//取消 按钮上的test外还有个不知所云的框
3,UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.updateComponentTreeUI(this); 这句不能少,否则没用
4, myButton.setForeground(Color.pink);
myButton.setBackground(Color.blue); 改变颜色
*/