用 jformdesigner 画出来的 RsyntaxTextArea 无法正确显示行数

2022-09-09 10:23:57 +08:00
 claysec

我用 jformdesigner 设计了一个界面,并且开启了显示行数,当前 ui 也有行数显示,如下 但是在我运行起来之后就没有行数显示了 刚开始以为是 Flat 皮肤和 Mig 布局问题 但是我使用官方 demo 进行测试时候发现是可以显示行数的。

所以我不知道怎么解决这个问题了。找遍全网也没有类似的问题,

测试代码:


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import net.miginfocom.swing.*;
import org.fife.ui.rsyntaxtextarea.*;
import org.fife.ui.rtextarea.*;

/**
 * @author unknown
 */
public class Database extends JFrame {
    public Database() {
        initComponents();
    }

    private void createUIComponents() {
        // TODO: add custom component creation code here
    }

    private void commonSql(ActionEvent e) {
        if(leftSplitPane.getDividerLocation() == 0){
            leftSplitPane.setDividerLocation(180);
        }else {
            leftSplitPane.setDividerLocation(0);
        }

    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        leftSplitPane = new JSplitPane();
        scrollPane1 = new JScrollPane();
        commonSQLStatementslLst = new JList();
        splitPane2 = new JSplitPane();
        panel1 = new JPanel();
        rTextScrollPane1 = new RTextScrollPane();
        sqlTextArea = new RSyntaxTextArea();
        label1 = new JLabel();
        encodeComboBox = new JComboBox<>();
        runSqlButton = new JButton();
        commonSqlButton = new JButton();
        scrollPane2 = new JScrollPane();
        sqlResutlTable = new JTable();

        //======== this ========
        Container contentPane = getContentPane();
        contentPane.setLayout(new CardLayout());

        //======== leftSplitPane ========
        {
            leftSplitPane.setDividerLocation(0);

            //======== scrollPane1 ========
            {
                scrollPane1.setViewportView(commonSQLStatementslLst);
            }
            leftSplitPane.setLeftComponent(scrollPane1);

            //======== splitPane2 ========
            {
                splitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT);
                splitPane2.setDividerLocation(160);

                //======== panel1 ========
                {
                    panel1.setLayout(new MigLayout(
                        "insets 0,hidemode 3",
                        // columns
                        "[fill]" +
                        "[fill]" +
                        "[fill]" +
                        "[fill]" +
                        "[grow,fill]",
                        // rows
                        "[grow,fill]" +
                        "[]"));

                    //======== rTextScrollPane1 ========
                    {
                        rTextScrollPane1.setLineNumbersEnabled(true);

                        //---- sqlTextArea ----
                        sqlTextArea.setParserDelay(0);
                        sqlTextArea.setSyntaxEditingStyle("text/sql");
                        rTextScrollPane1.setViewportView(sqlTextArea);
                    }
                    panel1.add(rTextScrollPane1, "cell 0 0 5 1");

                    //---- label1 ----
                    label1.setText("\u7f16\u7801:");
                    panel1.add(label1, "cell 0 1");

                    //---- encodeComboBox ----
                    encodeComboBox.setModel(new DefaultComboBoxModel<>(new String[] {
                        "UTF-8",
                        "GBK",
                        "GB2312"
                    }));
                    panel1.add(encodeComboBox, "cell 1 1");

                    //---- runSqlButton ----
                    runSqlButton.setText("\u8fd0\u884c");
                    panel1.add(runSqlButton, "cell 2 1");

                    //---- commonSqlButton ----
                    commonSqlButton.setText("\u5e38\u7528SQL\u8bed\u53e5");
                    commonSqlButton.addActionListener(e -> commonSql(e));
                    panel1.add(commonSqlButton, "cell 3 1");
                }
                splitPane2.setTopComponent(panel1);

                //======== scrollPane2 ========
                {
                    scrollPane2.setViewportView(sqlResutlTable);
                }
                splitPane2.setBottomComponent(scrollPane2);
            }
            leftSplitPane.setRightComponent(splitPane2);
        }
        contentPane.add(leftSplitPane, "card1");
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JSplitPane leftSplitPane;
    private JScrollPane scrollPane1;
    private JList commonSQLStatementslLst;
    private JSplitPane splitPane2;
    private JPanel panel1;
    private RTextScrollPane rTextScrollPane1;
    private RSyntaxTextArea sqlTextArea;
    private JLabel label1;
    private JComboBox<String> encodeComboBox;
    private JButton runSqlButton;
    private JButton commonSqlButton;
    private JScrollPane scrollPane2;
    private JTable sqlResutlTable;
    // JFormDesigner - End of variables declaration  //GEN-END:variables

    public static void main(String[] args) {
        new Database().setVisible(true);

    }
}

希望各位大佬能够帮忙看看是怎么回事。这事困扰我好久了

935 次点击
所在节点    Java
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/878829

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX