
JScrollPane不能用add追加内部panel,JScrollPane设置颜色没有意义
你可以直接在实例化的时候就添加JTextArea.JTextArea jt=new JTextArea("反清复明")
JSrollPane js=new JScrollPane(jt)
setViewportView
public void setViewportView(Component view)创建一个视口(如果有必要)并设置其视图。不直接为 JScrollPane 构造方法提供视图的应用程序应使用此方法指定将显示在滚动窗格中的滚动组件子级。例如:
JScrollPane scrollpane = new JScrollPane()
scrollpane.setViewportView(myBigComponentToScroll)
***应用程序不应将子级直接添加到滚动窗格。***
摘自JDK5.0
import java.awt.*import java.awt.event.*
import javax.swing.*
public class JScrollPaneDemo
{
JScrollPane scrollPane
public JScrollPaneDemo()
{
JFrame f = new JFrame("JScrollpane1")
Container contentPane = f.getContentPane()
JLabel label = new JLabel("Label")
JButton btn = new JButton("Button")
JPanel panel = new JPanel()
panel.setLayout(new BorderLayout())
panel.add(label, BorderLayout.CENTER)
panel.add(btn, BorderLayout.SOUTH)
scrollPane = new JScrollPane(panel)
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS)
contentPane.add(scrollPane, BorderLayout.CENTER)
f.setSize(new Dimension(350, 220))
f.pack()
f.setVisible(true)
}
public static void main(String[] args)
{
new JScrollPaneDemo()
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)