怎么用图片做背景啊~~~~~~~ 还有怎么用代码画渐变色? 怎么用图片做背景啊~~~~~~~ 还有怎么用代码画渐变色? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用图片做背景自己用drawImage画吧用代码画渐变色,给你个示例,其实在JDK的DEMO中也有的Graphics2D graphics = (Graphics2D) image.getGraphics();GradientPaint gradient = new GradientPaint(transitionStart, 0, leftColor, transitionEnd, 0, rightColor);graphics.setPaint(gradient);graphics.fillRect(transitionStart, 0, transitionEnd - transitionStart, height); import javax.swing.*;import java.awt.*;import java.awt.event.*;public class Test{ private JFrame frame = new JFrame("背景图片测试"); private JPanel imagePanel ; private ImageIcon background; public static void main(String[] args) { new Test(); } public Test() { background = new ImageIcon("1.jpg");//背景图片 JLabel label = new JLabel(background);//把背景图片显示在一个标签里面 // 把标签的大小位置设置为图片刚好填充整个面板 label.setBounds(0,0,background.getIconWidth(),background.getIconHeight()); // 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明 imagePanel = (JPanel)frame.getContentPane(); imagePanel.setOpaque(false); // 内容窗格默认的布局管理器为BorderLayout imagePanel.setLayout(new FlowLayout()); imagePanel.add(new JButton("测试按钮")); frame.getLayeredPane().setLayout(null); // 把背景图片添加到分层窗格的最底层作为背景 frame.getLayeredPane().add(label,new Integer(Integer.MIN_VALUE)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(background.getIconWidth(),background.getIconHeight()); frame.setVisible(true); }} JSpinner 获取焦点问题 子类继承父类,能得到父类中的静态内部类吗 获得当前日期是今年的第几周? 方法块的左括号应该“同一行接着写”还是“另起一行”? wml文件中调用wmls文件中的脚本 [求助]String的问题 问焦点事件永久性和暂时性的区别??? 用sql2000的三个驱动jar文件能够连接到sql7.0码? 怎样获取本地目录下某个文件的大小? 问个正则表达式的问题 jsp 连接问题,来啊 运行jar 出现问题......
自己用drawImage画吧用代码画渐变色,给你个示例,其实在JDK的DEMO中也有的
Graphics2D graphics = (Graphics2D) image.getGraphics();
GradientPaint gradient = new GradientPaint(transitionStart, 0, leftColor, transitionEnd, 0, rightColor);
graphics.setPaint(gradient);
graphics.fillRect(transitionStart, 0, transitionEnd - transitionStart, height);
import java.awt.*;
import java.awt.event.*;public class Test
{ private JFrame frame = new JFrame("背景图片测试");
private JPanel imagePanel ;
private ImageIcon background;
public static void main(String[] args)
{
new Test();
}
public Test()
{
background = new ImageIcon("1.jpg");//背景图片
JLabel label = new JLabel(background);//把背景图片显示在一个标签里面
// 把标签的大小位置设置为图片刚好填充整个面板
label.setBounds(0,0,background.getIconWidth(),background.getIconHeight());
// 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明
imagePanel = (JPanel)frame.getContentPane();
imagePanel.setOpaque(false);
// 内容窗格默认的布局管理器为BorderLayout
imagePanel.setLayout(new FlowLayout());
imagePanel.add(new JButton("测试按钮"));
frame.getLayeredPane().setLayout(null);
// 把背景图片添加到分层窗格的最底层作为背景
frame.getLayeredPane().add(label,new Integer(Integer.MIN_VALUE));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(background.getIconWidth(),background.getIconHeight());
frame.setVisible(true);
}
}