JFrame中如何显示滚动条 怎样才能在JFrame中加入滚动条!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 JTextArea text = new JTextArea();JScrollPane sp = new JScrollPane(text);frame.getContentPane().add(sp); 我的意思是,给整个JFrame窗口加上滚动条! 这就是给JFrame窗口加滚动,如果的想法是把JFrame放到JScrollPane中,那么不可能。不太清楚你的意思,把你想实现的效果详细描述一下吧 我现在有一个Swing的程序,当系统设置为1024*768时,JFrame里的button可以正常显示。当系统设置为800*600时,有的button看不到了。我想加一个滚动条,在800*600时也可以看到button 那是ContentPane好不好...你说JFRAME....怎么可能把JFRAME装进来... import javax.swing.JFrame;import java.awt.Container;import javax.swing.JScrollPane;public class test extends JFrame { public test() { JScrollPane a=new JScrollPane(); Container contentPane=this.getContentPane(); contentPane.add(a); } public static void main(String[] arsg) { try { test aa= new test(); aa.setVisible(true); } catch (Exception e) { } }}这样就可以了然后在JScrollPane a 里面添加东西只要超过范围滚动条就出来不超范围就不出来 就是这样呀,把内容面板加入JScrollPane,然后把你要加入的内容全部加到里面呀 把所有的内容都加到JScrollPane里面,那样就相当于对JFrame加滚动条啦 可以有直接的滚动条,叫JScrollBar类。你可以试试看。 import java.awt.*;import java.awt.event.*;import javax.swing.*;/** * * @author 1 */public class ScrollBarExample1 extends JPanel{ JLabel label; /** Creates a new instance of ScrollBarExample1 */ public ScrollBarExample1() { super(true); label = new JLabel(); setLayout(new BorderLayout()); JScrollBar hbar = new JScrollBar(JScrollBar.HORIZONTAL, 30, 20, 0, 300); JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 300); hbar.setUnitIncrement(2); vbar.setBlockIncrement(1); hbar.addAdjustmentListener(new MyAdjustmentListener()); vbar.addAdjustmentListener(new MyAdjustmentListener()); add(hbar, BorderLayout.SOUTH); add(vbar, BorderLayout.EAST); add(label, BorderLayout.CENTER); } class MyAdjustmentListener implements AdjustmentListener { public void adjustmentValueChanged(AdjustmentEvent e) { label.setText("" + e.getValue()); repaint(); } } public static void main(String s[]) { JFrame frame = new JFrame("Scroll Bar Example"); ScrollBarExample1 jcrollBar = new ScrollBarExample1(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(jcrollBar); frame.setSize(200, 200); frame.setVisible(true); }} 单对单互发信息聊天 socket 线程 高手们,菜鸟诚心求教 vector类型的数据在JTable显示问题 关于java中的HTML.Tag,在线等!!! 为什么用validate()不能刷新我的JFrame对象?(内有代码,很短,麻烦请大家看一下吧~) 【请教高手】如何判断客户机是否安装Java运行环境? ~~~~~~~急求jxl.jar包 请问怎么用installanywhere 散分!!ResultSet中的绝对定位 解析服务器的字节数组问题 请问有没有工具可以把C#的代码转换成java的代码? 帮忙写个算法,谢谢
JScrollPane sp = new JScrollPane(text);
frame.getContentPane().add(sp);
不太清楚你的意思,把你想实现的效果详细描述一下吧
你说JFRAME....怎么可能把JFRAME装进来...
import java.awt.Container;
import javax.swing.JScrollPane;public class test
extends JFrame {
public test() {
JScrollPane a=new JScrollPane();
Container contentPane=this.getContentPane();
contentPane.add(a);
} public static void main(String[] arsg) {
try {
test aa= new test(); aa.setVisible(true);
}
catch (Exception e) {
}
}}
这样就可以了
然后在JScrollPane a 里面添加东西
只要超过范围滚动条就出来
不超范围就不出来
import java.awt.event.*;
import javax.swing.*;/**
*
* @author 1
*/
public class ScrollBarExample1 extends JPanel{
JLabel label;
/** Creates a new instance of ScrollBarExample1 */
public ScrollBarExample1()
{
super(true);
label = new JLabel();
setLayout(new BorderLayout());
JScrollBar hbar = new JScrollBar(JScrollBar.HORIZONTAL, 30, 20, 0, 300);
JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 300);
hbar.setUnitIncrement(2);
vbar.setBlockIncrement(1);
hbar.addAdjustmentListener(new MyAdjustmentListener());
vbar.addAdjustmentListener(new MyAdjustmentListener());
add(hbar, BorderLayout.SOUTH);
add(vbar, BorderLayout.EAST);
add(label, BorderLayout.CENTER);
}
class MyAdjustmentListener implements AdjustmentListener
{
public void adjustmentValueChanged(AdjustmentEvent e)
{
label.setText("" + e.getValue());
repaint();
}
} public static void main(String s[])
{
JFrame frame = new JFrame("Scroll Bar Example");
ScrollBarExample1 jcrollBar = new ScrollBarExample1();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(jcrollBar);
frame.setSize(200, 200);
frame.setVisible(true);
}
}