当JTextField
处于JScrollPanel
,如果面板已滚动,每当从JComboBox
下拉是在JTextField
之后,文本字段示出了通过下拉菜单。 的JTextField通过JcomboBox的下拉表示滚动
This only发生在内容滚动后(不在应用程序启动时)。
主要问题是我们该如何解决这个问题? 奖励积分,如果答案:
- 是不是黑客攻击
- 解释为什么它摆在首位
事情我已经试过发生:
- 移动滚动窗格外的下拉列表(无变化)
- 将重绘添加到任何ND每个集装箱我能找到的滚动(无变化)
- 不同的布局管理器为滚动窗格的内容(无变化)
代码示例:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextFieldShowsThrough{
public static void main(String[] args){
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(createScrollDemo());
frame.pack();
// For demonstration purposes
frame.setSize(frame.getWidth() + 100, frame.getHeight() - 100);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static JScrollPane createScrollDemo(){
final Box optionsPanel = Box.createVerticalBox();
optionsPanel.add(createDropDown());
optionsPanel.add(createTextField("Option1"));
optionsPanel.add(createTextField("Option2"));
optionsPanel.add(createTextField("Option3"));
optionsPanel.add(createTextField("Option4"));
optionsPanel.add(createTextField("Option5"));
optionsPanel.add(Box.createVerticalGlue());
JScrollPane result = new JScrollPane(optionsPanel);
// Made attempts to fix here, but to no avail
/*result.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
result.repaint();
}
});*/
return result;
}
public static Box createDropDown(){
Box b = Box.createVerticalBox();
b.setAlignmentX(JLabel.LEFT_ALIGNMENT);
b.add(new JLabel("Language"));
JComboBox combo = new JComboBox(new String[]{"en", "fr", "es"});
combo.setMaximumSize(new Dimension(500, 25));
b.add(combo);
return b;
}
public static Box createTextField(String label){
Box mainBox = Box.createVerticalBox();
mainBox.setOpaque(true);
mainBox.setBackground(new Color((int)(Math.random() * 0x1000000))); // because fun
JLabel jLabel = new JLabel(label);
jLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
mainBox.add(jLabel);
Box secondaryBox = Box.createHorizontalBox();
secondaryBox.setAlignmentX(JLabel.LEFT_ALIGNMENT);
TextField tf = new TextField();
tf.setMaximumSize(new Dimension(500, 25));
secondaryBox.add(tf);
mainBox.add(secondaryBox);
return mainBox;
}
}
滑稽你如何能错过当看别人的代码时,这个小“J”。易于修复,很好的答案。将尽快接受。 –
我假设你的意思是[this](http://stackoverflow.com/questions/33899843/the-jscrollpane-content-doesnt-refesh-while-scrolling/33904482#33904482)代码? – MadProgrammer
:是的 - 问题中有问题(刷新的东西?)我无法复制,所以我不能“修复”这个问题,但它确实引发了好奇心。 –