Je crée un JTextPane
simple et en définissant un texte long après le paramètre viewport, mais lorsque j'exécute un programme sous Mac OS 10.11.5, mes lignes de texte JTextPane
se replient les unes avec les autres. Quand je défile lentement, ça n'arrive pas, mais quand je défile un peu vite, ça commence à s'effondrer. Ce problème ne se produit pas dans Windows. Voici mon exemple de code source:JTextPane texte se repliant sur défilement dans Mac OS
public class JTextPaneScroll extends javax.swing.JFrame {
private String s = "Wait! Some of your past questions have not been well-received, and you're in danger of being blocked from asking any more.\n"
+ "\n For help formulating a clear, useful question, see: How do I ask a good question?\n"
+ "Also, edit your previous questions to improve formatting and clarity."
+ "Wait! Some of your past questions have not been well-received, and you're in danger of being blocked from asking any more.\n"
+ "\n For help formulating a clear, useful question, see: How do I ask a good question?\n"
+ "Also, edit your previous questions to improve formatting and clarity."
+ "Wait! Some of your past questions have not been well-received, and you're in danger of being blocked from asking any more.\n"
+ "\n For help formulating a clear, useful question, see: How do I ask a good question?\n"
+ "Also, edit your previous questions to improve formatting and clarity.";
public JTextPaneScroll() {
initComponents();
setTextToPane();
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jspcomp = new javax.swing.JScrollPane();
comp = new javax.swing.JTextPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jspcomp.setViewportView(comp);
getContentPane().add(jspcomp, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 20, 290, 180));
pack();
}// </editor-fold>
private void setTextToPane() {
try {
comp.setText(s);
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* @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 {
javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(JTextPaneScroll.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(JTextPaneScroll.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(JTextPaneScroll.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(JTextPaneScroll.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 JTextPaneScroll().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextPane comp;
private javax.swing.JScrollPane jspcomp;
// End of variables declaration
}
'getContentPane() setLayout (nouveau org.netbeans.lib.awtextra.AbsoluteLayout());.' 'Le AbsoluteLayout' est vraiment juste une façon de dire « non disposition'. Les interfaces graphiques Java doivent fonctionner sur différents systèmes d'exploitation, taille d'écran, résolution d'écran, etc., en utilisant différents PLAF dans différents environnements locaux. En tant que tels, ils ne sont pas propices à la mise en page pixel parfait. Utilisez plutôt des gestionnaires de disposition, ou [des combinaisons de ceux-ci] (http://stackoverflow.com/a/5630271/418556) avec un remplissage de mise en page et des bordures pour [espace blanc] (http://stackoverflow.com/a/17874718/ 418556). –
j'ai essayé cela aussi avec BorderLayout, et ai également essayé avec placer le document stylé. mais toujours confronté au même problème. – user3098231
* "essayé aussi avec BorderLayout" * Je serais prêt à aider à corriger cette version. Où est-ce? –