java中滚动条如何 java中滚动条如何显示他的最大(小)值,并且改变文本区的颜色急急急急急急!!!!!!!!!!!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 java中滚动条如何显示他的最大(小)值看不懂…… 用JScrollPane组件面板,然后添加文本组件进入面板。相关操作请查API文档。 JSlider slider = new JSlider(30,200);slider.setPaintTicks(true); 代码如下:具有滚动效果的:JTextArea text = new JTextArea();JScrollPane scroll = new JScrollPane(text);this.getContentPane().add(scroll,BorderLayout.CENTER); JTextArea text = new JTextArea();this.getContentPane().add(new JScrollPane(text),BorderLayout.CENTER);接6楼,这样亦可。 没看懂你说的是什么意思!写清楚点,你要在哪里实现滚动条.设置颜色,你就好好看看文本类的api 或是其父类的. 你是说的在Java Swing中的进度条么?如果是的话 类似的我以前也做过。。 //进度条 JProgressBar progressBar = new JProgressBar(JProgressBar.HORIZONTAL); progressBar.setForeground(Color.red);//进度条的run方法 public void run() { try { this.setTitle("正在登陆"); this.progressBar.setStringPainted(true); for(int i =0 ;i<=100;i=i+3) { this.progressBar.setValue(i); Thread.sleep(200); } this.dispose(); JOptionPane.showMessageDialog( null,"恭喜您!!\n登陆成功!")); new MainFrame(loginbean1); } catch (InterruptedException e) { e.printStackTrace(); } } 这是我以前项目中的一个Java文件 其中进度条包含在里边 在此与你共享一下 图片的路径可删掉代码如下:package com.salarymanager.ui;import java.awt.Color;import java.awt.Container;import java.awt.Font;import java.awt.Image;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.util.Random;import java.util.Vector;import javax.swing.BoxLayout;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JProgressBar;import javax.swing.JTextField;import com.salarymanager.bean.loginBean;import com.salarymanager.dao.LoginDAO;public class LoginFrame extends JFrame implements ActionListener,Runnable,KeyListener,MouseListener{ JLabel lbl_title = new JLabel(new ImageIcon(".\\images\\欢迎使用.gif")); JLabel lbl_username = new JLabel("用 户 名:"); JTextField txt_username = new JTextField(13); JLabel lbl_pwd = new JLabel("用户密码:"); JPasswordField txt_pwd = new JPasswordField(13); JButton btn_updatepwd = new JButton("修改密码 ?",new ImageIcon(".\\images\\restore.png")); JButton btn_misspwd = new JButton("忘了密码 ?",new ImageIcon(".\\images\\help.png")); JPanel Panel_miss = new JPanel(); //随机数发生器 //验证码 JLabel lbl_validate = new JLabel("验证码:"); JTextField txt_validate = new JTextField(4); JButton btn_next = new JButton("看不清"); JTextField txt_next = new JTextField(4); JPanel Panel_next = new JPanel(); //3个控件区 JButton btn_load = new JButton("登 陆(A)",new ImageIcon(".\\images\\branch.png")); JButton btn_reg = new JButton("注 册(R)",new ImageIcon(".\\images\\Attendance.png")); JButton btn_exit = new JButton("清 空(E)",new ImageIcon(".\\images\\edit.png")); JPanel panel_title = new JPanel(); JPanel panel_username = new JPanel(); JPanel panel_pwd = new JPanel(); JPanel panel_btn = new JPanel(); // Lucida Handwriting Curlz MT Bookshelf Symbol 7 Edwardian Script ITC Font font0=new Font("Kristen ITC",Font.ITALIC,18); Font font1=new Font("隶书",Font.TRUETYPE_FONT,20); Font font2=new Font("隶书",Font.BOLD,16); //进度条 JProgressBar progressBar = new JProgressBar(JProgressBar.HORIZONTAL); public LoginFrame() { super("工资管理系统"); Container con = this.getContentPane(); con.setLayout(new BoxLayout(con,BoxLayout.Y_AXIS)); this.setLocation(350,239); lbl_title.setFont(font1); lbl_title.setForeground(Color.RED); panel_title.add(lbl_title); panel_username.add(lbl_username); panel_username.add(txt_username); lbl_username.setForeground(Color.blue); txt_username.setForeground(Color.blue); txt_username.setFont(font2); txt_username.setForeground(Color.BLUE); //密码段 panel_pwd.add(lbl_pwd); panel_pwd.add(txt_pwd); lbl_pwd.setForeground(Color.blue); txt_pwd.setForeground(Color.red); txt_pwd.setFont(font2); txt_pwd.setEchoChar('◆'); //注册段 txt_validate.setFont(font0); txt_validate.setForeground(Color.blue); txt_validate.setBackground(Color.pink); //设置 “下一个” 控件的内容 Panel_next.add(lbl_validate); Panel_next.add(txt_validate); Panel_next.add(btn_next); Panel_next.add(txt_next); //txt_next.setText(rand()); txt_next.setEditable(false); txt_next.setFont(font0); txt_next.setForeground(Color.blue); txt_next.setBackground(Color.pink); //3个按钮段 panel_btn.add(btn_load); panel_btn.add(btn_reg); panel_btn.add(btn_exit); //忘了密码段 Panel_miss.add(btn_updatepwd); Panel_miss.add(btn_misspwd); progressBar.setForeground(Color.red); this.add(panel_title); this.add(panel_username); this.add(panel_pwd); this.add(Panel_next); this.add(Panel_miss); this.add(panel_btn); this.add(progressBar); this.txt_username.addMouseListener(this); this.btn_load.addActionListener(this); this.btn_exit.addActionListener(this); this.btn_reg.addActionListener(this); this.btn_next.addActionListener(this); this.btn_updatepwd.addActionListener(this); this.btn_misspwd.addActionListener(this); this.txt_username.addKeyListener(this); this.txt_pwd.addKeyListener(this); this.txt_validate.addKeyListener(this); //设置登录按钮的快捷键alt+a this.btn_load.setMnemonic(KeyEvent.VK_A); //设置注册按钮的快捷键alt+r this.btn_reg.setMnemonic(KeyEvent.VK_R); //设置退出按钮的快捷键alt+e this.btn_exit.setMnemonic(KeyEvent.VK_E); //先得到文件中的图标 Toolkit tool = Toolkit.getDefaultToolkit(); Image image = tool.getImage(".\\images\\QQ.jpg"); //修改当前的窗口的图标 this.setIconImage(image); this.pack(); //this.setSize(350,300); //关闭窗口 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //设置窗口大小不能改变 this.setResizable(false); this.setVisible(true); this.setResizable(false); //this.pack(); this.rand(); } //随机字符段 public void rand() { Random random = new Random(); String str1 = String.valueOf(random.nextInt(10)); String str2 = String.valueOf(random.nextInt(10)); char char3 = (char)(random.nextInt(26)+97); char char4 = (char)(random.nextInt(26)+65); int ran = random.nextInt(5)+1; if(ran==1) { txt_next.setText(char3+str1+str2+char4); } if(ran==2) { txt_next.setText(str1+char3+str2+char4); } if(ran==3) { txt_next.setText(str1+char4+str2+char3); } if(ran==4) { txt_next.setText(char4+str2+str1+char3); } if(ran==5) { txt_next.setText(str2+char4+str1+char3); } } loginBean loginbean1 = null; //进度条的run方法 public void run() { try { this.setTitle("正在登陆"); this.progressBar.setStringPainted(true); //用循环使进度条的大小 每次加3地递增 也可以因个人而异 进行设定 for(int i =0 ;i<=100;i=i+3) { //设置进度条的进度值大小 this.progressBar.setValue(i); //设置线程的时间间隔 Thread.sleep(200); } //进行销毁 释放资源 this.dispose(); JOptionPane.showMessageDialog( null,"恭喜您!!\n登陆成功!!\n欢迎您==》 "+ loginbean1.getUsername(),getName(), getDefaultCloseOperation(), new ImageIcon(".\\images\\QQ.jpg")); new MainFrame(loginbean1); } catch (InterruptedException e) { e.printStackTrace(); } } public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); new LoginFrame(); } public void actionPerformed(ActionEvent e) { if(e.getSource() == btn_load) { //定义2个变量来接受得到的数据 String name = txt_username.getText(); String pwd = txt_pwd.getText(); String validatepwd = txt_validate.getText(); if(name.equals("")||pwd.equals("")) { JOptionPane.showMessageDialog(null,"Sorry!\n用户名或密码为空!!","温馨提示",JOptionPane.WARNING_MESSAGE,new ImageIcon(".\\images\\200651897916612.gif")); } else { //不区分大小写/(在此得到看不清的值) if(validatepwd.equals("")||!validatepwd.equalsIgnoreCase(txt_next.getText())) { JOptionPane.showMessageDialog(this,"验证码不能为空"); } else { //把从文本框中得到的信息放到JavaBean中 loginBean loginbean = new loginBean(); loginbean.setUsername(name); loginbean.setPassword(pwd); //创建用户的数据访问层对象 LoginDAO logindao = new LoginDAO(); //根据列表的大小来判断 Vector<loginBean> Vector vec = (Vector)logindao.findAll(loginbean); if(vec.size()>0)//2006518915133429.gif { loginbean1 =(loginBean)vec.get(0); new Thread(this).start(); //隐藏当前的窗口 } else { JOptionPane.showMessageDialog(null,"Sorry!\n登录失败!!","错误警告",JOptionPane.WARNING_MESSAGE,new ImageIcon(".\\images\\2006518944869409.gif")); this.txt_username.setText(null); this.txt_pwd.setText(null); this.txt_validate.setText(null); } } } } else if(e.getSource() == btn_reg) { JOptionPane.showMessageDialog(this,"欢迎进入新用户注册系统",getName(), getDefaultCloseOperation(), new ImageIcon(".\\images\\200651710234019333.gif") ); this.setVisible(false); //导出注册窗口 RegisterFrame reg = new RegisterFrame(); } else if(e.getSource() == btn_exit) { this.txt_username.setText(null); this.txt_pwd.setText(null); } else if(e.getSource() == btn_next){ this.rand(); } else if(e.getSource() == btn_misspwd) { JOptionPane.showMessageDialog(this,"欢迎进入用户找回密码系统",getName(), getDefaultCloseOperation(), new ImageIcon(".\\images\\20065188595083271.gif") ); //隐藏当前的窗口 this.txt_username.getText() this.setVisible(false); new Findpassword(); } else if(e.getSource() == btn_updatepwd) { JOptionPane.showMessageDialog(this,"欢迎进入用户改密系统" ,getName(), getDefaultCloseOperation(), new ImageIcon(".\\images\\2006518902319594.gif")); //隐藏当前的窗口 this.setVisible(false); new UpDatepassword(this.txt_username.getText()); } } public void keyPressed(KeyEvent e) { if(e.getKeyCode()==10){ btn_load.doClick(); } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { // TODO Auto-generated method stub } public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { if(e.getSource()==txt_username) { //txt_username.get } } public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub }} 空指针异常求解 需要导入(import)什么,才能编译通过f.add(new Button("ok"),NORTH); java GUI,下面这段代码生成的Frame的大小和我所设置的不同 java 修改数据库内容的语句 jsp传递中文参数乱码问题 网络编程问题 HashMap的存放的值能不能是一个hashTable? appletviewer的应用 怎么从文件里读中文? applet如何从数据库中取数据? 我连数据库的时候,报个空指针出来? 真的是找不到原因所在。求大虾们帮帮忙 一道java题,帮忙看下
JSlider slider = new JSlider(30,200);
slider.setPaintTicks(true);
JScrollPane scroll = new JScrollPane(text);
this.getContentPane().add(scroll,BorderLayout.CENTER);
JTextArea text = new JTextArea();
this.getContentPane().add(new JScrollPane(text),BorderLayout.CENTER);
接6楼,这样亦可。
写清楚点,你要在哪里实现滚动条.
设置颜色,你就好好看看文本类的api 或是其父类的.
如果是的话 类似的我以前也做过。。
JProgressBar progressBar = new JProgressBar(JProgressBar.HORIZONTAL);
progressBar.setForeground(Color.red);//进度条的run方法
public void run()
{
try {
this.setTitle("正在登陆");
this.progressBar.setStringPainted(true);
for(int i =0 ;i<=100;i=i+3)
{
this.progressBar.setValue(i);
Thread.sleep(200);
}
this.dispose();
JOptionPane.showMessageDialog( null,"恭喜您!!\n登陆成功!"));
new MainFrame(loginbean1);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
代码如下:
package com.salarymanager.ui;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;
import java.util.Vector;import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JProgressBar;
import javax.swing.JTextField;import com.salarymanager.bean.loginBean;
import com.salarymanager.dao.LoginDAO;public class LoginFrame extends JFrame implements ActionListener,Runnable,KeyListener,MouseListener{
JLabel lbl_title = new JLabel(new ImageIcon(".\\images\\欢迎使用.gif"));
JLabel lbl_username = new JLabel("用 户 名:");
JTextField txt_username = new JTextField(13);
JLabel lbl_pwd = new JLabel("用户密码:");
JPasswordField txt_pwd = new JPasswordField(13);
JButton btn_updatepwd = new JButton("修改密码 ?",new ImageIcon(".\\images\\restore.png"));
JButton btn_misspwd = new JButton("忘了密码 ?",new ImageIcon(".\\images\\help.png"));
JPanel Panel_miss = new JPanel();
//随机数发生器
//验证码
JLabel lbl_validate = new JLabel("验证码:");
JTextField txt_validate = new JTextField(4);
JButton btn_next = new JButton("看不清");
JTextField txt_next = new JTextField(4);
JPanel Panel_next = new JPanel(); //3个控件区
JButton btn_load = new JButton("登 陆(A)",new ImageIcon(".\\images\\branch.png"));
JButton btn_reg = new JButton("注 册(R)",new ImageIcon(".\\images\\Attendance.png"));
JButton btn_exit = new JButton("清 空(E)",new ImageIcon(".\\images\\edit.png"));
JPanel panel_title = new JPanel();
JPanel panel_username = new JPanel();
JPanel panel_pwd = new JPanel();
JPanel panel_btn = new JPanel();
// Lucida Handwriting Curlz MT Bookshelf Symbol 7 Edwardian Script ITC
Font font0=new Font("Kristen ITC",Font.ITALIC,18);
Font font1=new Font("隶书",Font.TRUETYPE_FONT,20);
Font font2=new Font("隶书",Font.BOLD,16);
//进度条
JProgressBar progressBar = new JProgressBar(JProgressBar.HORIZONTAL);
public LoginFrame()
{
super("工资管理系统");
Container con = this.getContentPane();
con.setLayout(new BoxLayout(con,BoxLayout.Y_AXIS));
this.setLocation(350,239);
lbl_title.setFont(font1);
lbl_title.setForeground(Color.RED);
panel_title.add(lbl_title);
panel_username.add(lbl_username);
panel_username.add(txt_username);
lbl_username.setForeground(Color.blue);
txt_username.setForeground(Color.blue);
txt_username.setFont(font2);
txt_username.setForeground(Color.BLUE);
//密码段
panel_pwd.add(lbl_pwd);
panel_pwd.add(txt_pwd);
lbl_pwd.setForeground(Color.blue);
txt_pwd.setForeground(Color.red);
txt_pwd.setFont(font2);
txt_pwd.setEchoChar('◆');
//注册段
txt_validate.setFont(font0);
txt_validate.setForeground(Color.blue);
txt_validate.setBackground(Color.pink);
//设置 “下一个” 控件的内容
Panel_next.add(lbl_validate);
Panel_next.add(txt_validate);
Panel_next.add(btn_next);
Panel_next.add(txt_next);
//txt_next.setText(rand());
txt_next.setEditable(false);
txt_next.setFont(font0);
txt_next.setForeground(Color.blue);
txt_next.setBackground(Color.pink);
//3个按钮段
panel_btn.add(btn_load);
panel_btn.add(btn_reg);
panel_btn.add(btn_exit);
//忘了密码段
Panel_miss.add(btn_updatepwd);
Panel_miss.add(btn_misspwd);
progressBar.setForeground(Color.red);
this.add(panel_title);
this.add(panel_username);
this.add(panel_pwd);
this.add(Panel_next);
this.add(Panel_miss);
this.add(panel_btn);
this.add(progressBar);
this.txt_username.addMouseListener(this);
this.btn_load.addActionListener(this);
this.btn_exit.addActionListener(this);
this.btn_reg.addActionListener(this);
this.btn_next.addActionListener(this);
this.btn_updatepwd.addActionListener(this);
this.btn_misspwd.addActionListener(this);
this.txt_username.addKeyListener(this);
this.txt_pwd.addKeyListener(this);
this.txt_validate.addKeyListener(this);
//设置登录按钮的快捷键alt+a
this.btn_load.setMnemonic(KeyEvent.VK_A);
//设置注册按钮的快捷键alt+r
this.btn_reg.setMnemonic(KeyEvent.VK_R);
//设置退出按钮的快捷键alt+e
this.btn_exit.setMnemonic(KeyEvent.VK_E);
//先得到文件中的图标
Toolkit tool = Toolkit.getDefaultToolkit();
Image image = tool.getImage(".\\images\\QQ.jpg");
//修改当前的窗口的图标
this.setIconImage(image);
this.pack();
//this.setSize(350,300);
//关闭窗口
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//设置窗口大小不能改变
this.setResizable(false);
this.setVisible(true);
this.setResizable(false);
//this.pack();
this.rand();
}
//随机字符段
public void rand()
{
Random random = new Random();
String str1 = String.valueOf(random.nextInt(10));
String str2 = String.valueOf(random.nextInt(10));
char char3 = (char)(random.nextInt(26)+97);
char char4 = (char)(random.nextInt(26)+65);
int ran = random.nextInt(5)+1;
if(ran==1)
{
txt_next.setText(char3+str1+str2+char4);
}
if(ran==2)
{
txt_next.setText(str1+char3+str2+char4);
}
if(ran==3)
{
txt_next.setText(str1+char4+str2+char3);
}
if(ran==4)
{
txt_next.setText(char4+str2+str1+char3);
}
if(ran==5)
{
txt_next.setText(str2+char4+str1+char3);
}
}
loginBean loginbean1 = null;
//进度条的run方法
public void run()
{
try {
this.setTitle("正在登陆");
this.progressBar.setStringPainted(true);
//用循环使进度条的大小 每次加3地递增 也可以因个人而异 进行设定
for(int i =0 ;i<=100;i=i+3)
{ //设置进度条的进度值大小
this.progressBar.setValue(i);
//设置线程的时间间隔
Thread.sleep(200);
}
//进行销毁 释放资源
this.dispose();
JOptionPane.showMessageDialog( null,"恭喜您!!\n登陆成功!!\n欢迎您==》 "+ loginbean1.getUsername(),getName(), getDefaultCloseOperation(), new ImageIcon(".\\images\\QQ.jpg"));
new MainFrame(loginbean1);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
new LoginFrame();
} public void actionPerformed(ActionEvent e) {
if(e.getSource() == btn_load)
{
//定义2个变量来接受得到的数据
String name = txt_username.getText();
String pwd = txt_pwd.getText();
String validatepwd = txt_validate.getText();
if(name.equals("")||pwd.equals(""))
{
JOptionPane.showMessageDialog(null,"Sorry!\n用户名或密码为空!!","温馨提示",JOptionPane.WARNING_MESSAGE,new ImageIcon(".\\images\\200651897916612.gif"));
}
else
{
//不区分大小写/(在此得到看不清的值)
if(validatepwd.equals("")||!validatepwd.equalsIgnoreCase(txt_next.getText()))
{
JOptionPane.showMessageDialog(this,"验证码不能为空");
}
else
{
//把从文本框中得到的信息放到JavaBean中
loginBean loginbean = new loginBean();
loginbean.setUsername(name);
loginbean.setPassword(pwd);
//创建用户的数据访问层对象
LoginDAO logindao = new LoginDAO();
//根据列表的大小来判断 Vector<loginBean>
Vector vec = (Vector)logindao.findAll(loginbean);
if(vec.size()>0)//2006518915133429.gif
{
loginbean1 =(loginBean)vec.get(0);
new Thread(this).start();
//隐藏当前的窗口
}
else
{
JOptionPane.showMessageDialog(null,"Sorry!\n登录失败!!","错误警告",JOptionPane.WARNING_MESSAGE,new ImageIcon(".\\images\\2006518944869409.gif"));
this.txt_username.setText(null);
this.txt_pwd.setText(null);
this.txt_validate.setText(null);
}
}
}
}
else if(e.getSource() == btn_reg)
{
JOptionPane.showMessageDialog(this,"欢迎进入新用户注册系统",getName(), getDefaultCloseOperation(), new ImageIcon(".\\images\\200651710234019333.gif") );
this.setVisible(false);
//导出注册窗口
RegisterFrame reg = new RegisterFrame();
}
else if(e.getSource() == btn_exit)
{
this.txt_username.setText(null);
this.txt_pwd.setText(null);
}
else if(e.getSource() == btn_next){
this.rand();
}
else if(e.getSource() == btn_misspwd)
{
JOptionPane.showMessageDialog(this,"欢迎进入用户找回密码系统",getName(), getDefaultCloseOperation(), new ImageIcon(".\\images\\20065188595083271.gif") );
//隐藏当前的窗口 this.txt_username.getText()
this.setVisible(false);
new Findpassword();
}
else if(e.getSource() == btn_updatepwd)
{
JOptionPane.showMessageDialog(this,"欢迎进入用户改密系统" ,getName(), getDefaultCloseOperation(), new ImageIcon(".\\images\\2006518902319594.gif"));
//隐藏当前的窗口
this.setVisible(false);
new UpDatepassword(this.txt_username.getText());
}
}
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==10){
btn_load.doClick();
}
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
if(e.getSource()==txt_username)
{
//txt_username.get
}
}
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
}