Java JTextPane文本在Mac os中滚动时折叠
我正在创建一个简单的Java JTextPane文本在Mac os中滚动时折叠,java,macos,swing,operating-system,jtextpane,Java,Macos,Swing,Operating System,Jtextpane,我正在创建一个简单的JTextPane并在视口后设置一个长文本,但当我在Mac os 10.11.5中运行程序时,我的JTextPane文本行彼此折叠。当我慢慢滚动时,它不会发生,但当我稍微快速滚动时,它开始崩溃。windows中没有出现此问题。以下是我的示例源代码: public class JTextPaneScroll extends javax.swing.JFrame { private String s = "Wait! Some of your past question
JTextPane
并在视口后设置一个长文本,但当我在Mac os 10.11.5中运行程序时,我的JTextPane
文本行彼此折叠。当我慢慢滚动时,它不会发生,但当我稍微快速滚动时,它开始崩溃。windows中没有出现此问题。以下是我的示例源代码:
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
}
公共类JTextPaneScroll扩展了javax.swing.JFrame{
private String s=“等等!您过去的一些问题没有得到很好的回答,您有被阻止提问的危险。\n”
+\n如需帮助制定清晰、有用的问题,请参阅:如何提出好问题?\n
+此外,请编辑以前的问题以改进格式和清晰度
+等等!您过去的一些问题没有得到很好的回答,您有被阻止再问的危险。\n
+\n如需帮助制定清晰、有用的问题,请参阅:如何提出好问题?\n
+此外,请编辑以前的问题以改进格式和清晰度
+等等!您过去的一些问题没有得到很好的回答,您有被阻止再问的危险。\n
+\n如需帮助制定清晰、有用的问题,请参阅:如何提出好问题?\n
+“此外,请编辑以前的问题,以改进格式和清晰度。”;
公共JTextPaneScroll(){
初始化组件();
Settextopane();
}
//
私有组件(){
jspcomp=newjavax.swing.JScrollPane();
comp=newjavax.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,20290180));
包装();
}//
私有void setTextToPane(){
试一试{
公司设置文本;
}捕获(例外情况除外){
例如printStackTrace();
}
}
/**
*@param指定命令行参数
*/
公共静态void main(字符串参数[]){
/*设置Nimbus的外观和感觉*/
//
/*如果Nimbus(在JavaSE6中引入)不可用,请使用默认的外观。
*详情请参阅http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
试一试{
setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
}捕获(ClassNotFoundException ex){
java.util.logging.Logger.getLogger(JTextPaneScroll.class.getName()).log(java.util.logging.Level.SEVERE,null,ex);
}catch(实例化异常){
java.util.logging.Logger.getLogger(JTextPaneScroll.class.getName()).log(java.util.logging.Level.SEVERE,null,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);
}
//
/*创建并显示表单*/
invokeLater(new Runnable()){
公开募捐{
新的JTextPaneScroll().setVisible(true);
}
});
}
//变量声明-不修改
私有javax.swing.JTextPane comp;
私有javax.swing.JScrollPane jspcomp;
//变量结束声明
}
是可滚动的,因此您可以将其设置为您想要的任何首选大小,并且仍然可以使用您想要的任何布局。默认情况下,组件会添加到JFrame的BorderLayout.CENTER
。可以调整框架的大小以查看发生了什么
textPane = new javax.swing.JTextPane() {
@Override
public Dimension getPreferredScrollableViewportSize() {
return new Dimension(290, 192);
}
};
是可滚动的
,因此您可以将其设置为您想要的任何首选大小,并且仍然可以使用您想要的任何布局。默认情况下,组件会添加到JFrame的BorderLayout.CENTER
。可以调整框架的大小以查看发生了什么
textPane = new javax.swing.JTextPane() {
@Override
public Dimension getPreferredScrollableViewportSize() {
return new Dimension(290, 192);
}
};
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout())
绝对布局实际上只是一种说“没有布局”的奇特方式。Java GUI必须在不同的操作系统、屏幕大小、屏幕分辨率等上工作,在不同的地区使用不同的PLAF。因此,它们不利于像素完美布局。相反,可以使用布局管理器,或者与布局填充和边框一起使用。我也尝试过使用BorderLayout,也尝试过设置样式化文档。但仍然面临着同样的问题。“在BorderLayout中也尝试过”我准备帮助修复该版本。它在哪里?我的意思是,当我面对这个问题时,我认为这可能是因为布局管理器,所以我设置了布局。我在面板中添加了jscrollpane,并为该面板设置了BorderLayout。但它不起作用。然后我采取了不同的方法,为jtextpane设置了样式化文档,并使用“doc.insertString(0,content,attribute);”在文档中插入字符串,我再次遇到了文本折叠问题。“我的意思是…”我的意思是,如果null
布局中断,我就不能提供任何内容。我非常关心使用BorderLayout
的版本,并尝试帮助修复它。getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout())
绝对布局实际上只是一种说“没有布局”的奇特方式。Java GUI必须在不同的操作系统、屏幕大小、屏幕分辨率等上工作,在不同的地区使用不同的PLAF。因此,它们不利于像素完美布局。在里面