java - JFrame中的滚动窗格未显示
问题描述
我尝试在框架上放置滚动条,但它不起作用,我看不到滚动条。
这是我的代码:
Popup noticePopup = new Popup("Notice", 1500, 900);
JPanel noticePanel = new JPanel();
noticePanel.setPreferredSize(new Dimension(1500,1000));
List<List> ListNote = controller.Medicament.consultationNotice(medocSelectStr);
String noticeThis =null;
for(int n=0;n<ListNote.size();n++) {
noticeThis = (String) ListNote.get(n).get(1);
}
JTextArea noticeArea = new JTextArea(noticeThis);
noticePopup.add(noticePanel);
noticePanel.add(noticeArea);
JScrollPane jScrollPane = new JScrollPane( noticePanel);
// only a configuration to the jScrollPane...
jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
// Then, add the jScrollPane to your frame
noticePopup.getContentPane().add(jScrollPane);
JScrollPane scroll=new JScrollPane(noticePanel,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
noticePopup.getContentPane().add(scroll);
解决方案
您正在创建两个具有相同内容的滚动窗格:
JScrollPane jScrollPane = new JScrollPane( noticePanel);
和:
JScrollPane scroll=new JScrollPane(noticePanel,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
而且您将它们都添加到弹出窗口中,并且还将通知面板添加到弹出窗口中,因此需要删除很多代码
Popup noticePopup = new Popup("Notice", 1500, 900);
JPanel noticePanel = new JPanel();
noticePanel.setPreferredSize(new Dimension(1500,1000));
List<List> ListNote = controller.Medicament.consultationNotice(medocSelectStr);
String noticeThis =null;
for(int n=0;n<ListNote.size();n++) {
noticeThis = (String) ListNote.get(n).get(1);
}
JTextArea noticeArea = new JTextArea(noticeThis);
noticePanel.add(noticeArea);
JScrollPane scroll=new JScrollPane(noticePanel,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
noticePopup.getContentPane().add(scroll);
推荐阅读
- matlab - 如何连接电流测量?
- javascript - Angular RxJs Observable 流合并数据
- python - 使用带有多个组的 pandas 提取正则表达式
- php - 如何解析这种格式?
- android - Android 进度指示器在 for 循环中一次递增
- flutter - 颤振:异步等待
- c++ - 在数组中查找对,使得 a+b%10 = k
- javascript - 在 Dialogflow fullfilment 中发送丰富的消息
- reactjs - 刷新页面时反应组件消失(使用反应路由器)
- python-3.x - PyOpenCL 2020.1 - 设备端队列未实现