JScrollPane 中添加多个组件
importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjavax.swing.border....
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
public class UserMarking extends JScrollPane
{
JPanel markingJPanel = new JPanel();
JButton submitJButton = new JButton("确定");
public UserMarking()
{
JButton j1 = new JButton();
j1.setBounds(20,100,100,50);
JButton j2 = new JButton();
j2.setBounds(20,250,100,50);
JButton j3 = new JButton();
j3.setBounds(20,350,100,50);
JButton j4 = new JButton();
j4.setBounds(20,500,100,50);
markingJPanel.setLayout(null);
markingJPanel.setSize(200,800);
markingJPanel.add(j1);
markingJPanel.add(j2);
markingJPanel.add(j3);
markingJPanel.add(j4);
setSize(200,500);
setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
getViewport().setView(markingJPanel);
}
}
为什么显示不出滚动条,超出边界范围的JButton不能显示出来!
怎么可以添加多个组件,然后出现滚动条呢 ?
还是没有滚动条的出现啊 倒数第六有字行 f.setSize(300, 600); 改为 f.setSize(300, 300);
就没有显示了 ~ 展开
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
public class UserMarking extends JScrollPane
{
JPanel markingJPanel = new JPanel();
JButton submitJButton = new JButton("确定");
public UserMarking()
{
JButton j1 = new JButton();
j1.setBounds(20,100,100,50);
JButton j2 = new JButton();
j2.setBounds(20,250,100,50);
JButton j3 = new JButton();
j3.setBounds(20,350,100,50);
JButton j4 = new JButton();
j4.setBounds(20,500,100,50);
markingJPanel.setLayout(null);
markingJPanel.setSize(200,800);
markingJPanel.add(j1);
markingJPanel.add(j2);
markingJPanel.add(j3);
markingJPanel.add(j4);
setSize(200,500);
setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
getViewport().setView(markingJPanel);
}
}
为什么显示不出滚动条,超出边界范围的JButton不能显示出来!
怎么可以添加多个组件,然后出现滚动条呢 ?
还是没有滚动条的出现啊 倒数第六有字行 f.setSize(300, 600); 改为 f.setSize(300, 300);
就没有显示了 ~ 展开
1个回答
展开全部
package dang;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class UserMarking {
JPanel markingJPanel = new JPanel();
JButton submitJButton = new JButton("确定");
JFrame jf=new JFrame("Test");
public UserMarking()
{
JButton j1 = new JButton();
j1.setBounds(20,100,100,50);
JButton j2 = new JButton();
j2.setBounds(20,250,100,50);
JButton j3 = new JButton();
j3.setBounds(20,350,100,50);
JButton j4 = new JButton();
j4.setBounds(20,500,100,50);
markingJPanel.setLayout(null);
markingJPanel.add(j1);
markingJPanel.add(j2);
markingJPanel.add(j3);
markingJPanel.add(j4);
JScrollPane jp=new JScrollPane(markingJPanel);
jp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jp.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jf.setLocation(300, 100);
jf.setSize(300, 600);
jf.add(jp);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new UserMarking();
}
}
自己写的一个,不知道是不是楼主要的效果?希望对你有用!
参考资料:
http://zhidao.baidu.com/q?word=JScrollPane+&ct=17&pn=0&tn=ikaslist&rn=10&lm=0&fr=search
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class UserMarking {
JPanel markingJPanel = new JPanel();
JButton submitJButton = new JButton("确定");
JFrame jf=new JFrame("Test");
public UserMarking()
{
JButton j1 = new JButton();
j1.setBounds(20,100,100,50);
JButton j2 = new JButton();
j2.setBounds(20,250,100,50);
JButton j3 = new JButton();
j3.setBounds(20,350,100,50);
JButton j4 = new JButton();
j4.setBounds(20,500,100,50);
markingJPanel.setLayout(null);
markingJPanel.add(j1);
markingJPanel.add(j2);
markingJPanel.add(j3);
markingJPanel.add(j4);
JScrollPane jp=new JScrollPane(markingJPanel);
jp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jp.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jf.setLocation(300, 100);
jf.setSize(300, 600);
jf.add(jp);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new UserMarking();
}
}
自己写的一个,不知道是不是楼主要的效果?希望对你有用!
参考资料:
http://zhidao.baidu.com/q?word=JScrollPane+&ct=17&pn=0&tn=ikaslist&rn=10&lm=0&fr=search
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询