用jscrollpane产生了个带滚动条的panel 。但是在拖动滚动条的时候上面的控件用覆盖到btn1,下面的要覆盖掉btn2. 现在想拖动滚动条只是滚动panel里的btn,请问如何解决?
下为代码:import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;public class cc { public static void main(String[] args){ JFrame frm = new JFrame();
Panel p = new Panel();
p.setLayout(new GridLayout(100,0));
Button btn[] = new Button[100];
for (int k= 0;k<10;k++)
{
btn[k] = new Button(Integer.toString(k));
p.add(btn[k]);
}
JScrollPane sp = new JScrollPane(p);
frm.getContentPane().setLayout(new BorderLayout());
Button btn1 = new Button("a");
Button btn2 = new Button("b");
frm.getContentPane().add(btn1,BorderLayout.NORTH);
frm.getContentPane().add(sp,BorderLayout.CENTER);
frm.getContentPane().add(btn2,BorderLayout.SOUTH);
frm.setSize(400,400);
frm.show();
}
}
下为代码:import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;public class cc { public static void main(String[] args){ JFrame frm = new JFrame();
Panel p = new Panel();
p.setLayout(new GridLayout(100,0));
Button btn[] = new Button[100];
for (int k= 0;k<10;k++)
{
btn[k] = new Button(Integer.toString(k));
p.add(btn[k]);
}
JScrollPane sp = new JScrollPane(p);
frm.getContentPane().setLayout(new BorderLayout());
Button btn1 = new Button("a");
Button btn2 = new Button("b");
frm.getContentPane().add(btn1,BorderLayout.NORTH);
frm.getContentPane().add(sp,BorderLayout.CENTER);
frm.getContentPane().add(btn2,BorderLayout.SOUTH);
frm.setSize(400,400);
frm.show();
}
}
把Panel和Button该成JPanel,JButton。
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;public class cc { public static void main(String[] args) { JFrame frm = new JFrame();
frm.getContentPane().setLayout(new BorderLayout()); Button btn1 = new Button("a");
frm.getContentPane().add(btn1, BorderLayout.NORTH); JPanel p = new JPanel();
p.setLayout(new GridLayout(100, 0));
JButton btn[] = new JButton[100];
for (int k = 0; k < 10; k++) {
btn[k] = new JButton(Integer.toString(k));
p.add(btn[k]); }
JScrollPane sp = new JScrollPane(p);
frm.getContentPane().add(sp, BorderLayout.CENTER); Button btn2 = new Button("b");
frm.getContentPane().add(btn2, BorderLayout.SOUTH); frm.setSize(400, 400);
frm.show();
}}
想问哈 在java里面有象delphi里面的listview吗!?在其一行中添加checkbox和文本信息。