我已经在Netbeans 8.1(Java版本1.8.0_65)中编写了一个简单的程序,其中它发现了一个已发现文件的列表并将它们写入了一个jTextArea。这工作正常,除了有很多行写入jTextArea(即超过500行左右)时,滚动条中的拇指消失。我看到这个post描述的确切问题。当TextArea有很多行时,JScrollPane不会显示Nimbus L&F中的缩略图
这似乎是一个known issue有雨云大号& F和乡亲已经发布了这一解决方法如上,他们说,要解决这个问题,只是增加一行在后描述:
UIManager.getLookAndFeelDefaults().put("ScrollBar.minimumThumbSize", new Dimension(30, 30));
问题我的确是在哪里放这行代码?我已经尝试在创建jScrollPanel之前将它添加到initComponents中(如下面的代码所示)。
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
我清楚地挥舞着刚刚约尽量坚持它不理解我在做什么不同的地方,并且,没有:检查时,如果雨云可我也已经试过了if语句之后惊喜,不工作。
有人可以帮我确定这种解决方法行代码应该去哪里?
我的代码:
public class ViewFiles extends javax.swing.JFrame {
/**
* Creates new form ViewFiles
*/
public ViewFiles() {
initComponents();
}
public ViewFiles(ArrayList<DiscoveredFile> files){
initComponents();
discoveredFiles = files;
displayFiles();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
javax.swing.UIManager.getLookAndFeelDefaults().put("Scrollbar.minimumThumbSize", new Dimension(30,30));
jScrollPane1 = new javax.swing.JScrollPane();
viewFilesTextArea = new javax.swing.JTextArea();
viewFilesCloseButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
viewFilesTextArea.setColumns(20);
viewFilesTextArea.setRows(5);
jScrollPane1.setViewportView(viewFilesTextArea);
viewFilesCloseButton.setText("Close");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 656, Short.MAX_VALUE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(viewFilesCloseButton)
.addGap(29, 29, 29))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addComponent(viewFilesCloseButton)
.addContainerGap())
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(ViewFiles.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ViewFiles.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ViewFiles.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ViewFiles.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ViewFiles().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton viewFilesCloseButton;
private javax.swing.JTextArea viewFilesTextArea;
// End of variables declaration
private ArrayList<DiscoveredFile> discoveredFiles;
public void displayFiles() {
for (DiscoveredFile file : discoveredFiles){
viewFilesTextArea.append(file.getFullPath() + "\n");
}
}
}
* *使用'JList'代替。另请参阅[File Browser GUI](http://codereview.stackexchange.com/q/4446/7784),了解可能提供一些提示的文件浏览器(例如,良好的渲染器)。 –
谢谢。我固定了悬挂的括号,并且也会使用jlist。 – Monty
您可能需要查看“Scrollbar.minimumThumbSize”和“ScrollBar.minimumThumbSize”键之间的差异。 – aterai