From 1bda9524add969e315d870f284046ecf1097f956 Mon Sep 17 00:00:00 2001 From: 826220679@qq.com <826220679@qq.com> Date: 星期日, 24 八月 2025 18:01:25 +0800 Subject: [PATCH] 修改 --- src/dell_system/MessageViewPanel.java | 31 +++++++++++++++++++++++++++++-- 1 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/dell_system/MessageViewPanel.java b/src/dell_system/MessageViewPanel.java index aaab8a1..c99f8b2 100644 --- a/src/dell_system/MessageViewPanel.java +++ b/src/dell_system/MessageViewPanel.java @@ -12,7 +12,7 @@ import java.util.ResourceBundle; import dell_targets.Dell_tag; import publicsWay.Languages; -import publicsWay.UDPPortAReceiver; +import udptcp.UDPPortAReceiver; import udptcp.UDPPortBReceiver; public class MessageViewPanel extends JPanel { @@ -32,6 +32,9 @@ private JRadioButton rdoSendHex; private JRadioButton rdoSendAscii; private JCheckBox chkAppendNewline; + // 添加常量定义最大行数 + private static final int MAX_LINES = 10000; + private static final int TRIM_LINES = 5000; // 当超过最大行数时保留的行数 private static final ThreadLocal<StringBuilder> SB = ThreadLocal.withInitial(() -> new StringBuilder(256)); @@ -100,7 +103,7 @@ "ALL", "55AA01", "55AA02", "55AA03", "55AA05", "55AA07", "55AA0A", "55AA0C", "55AA12", "55AA14", "55AA20", - "GNGGA", "XTB" + "GNGGA", "XTB", "GBGGA", "SSGGA" }); protocolPanel.add(cbProtocol, BorderLayout.CENTER); add(protocolPanel, gbc); @@ -400,6 +403,18 @@ SwingUtilities.invokeLater(() -> { txtDataView.append(displayData.toString() + "\n"); + + // 检查并限制行数 + int lineCount = txtDataView.getLineCount(); + if (lineCount > MAX_LINES) { + try { + int end = txtDataView.getLineEndOffset(TRIM_LINES - 1); + txtDataView.replaceRange("", 0, end); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + txtDataView.setCaretPosition(txtDataView.getDocument().getLength()); }); } @@ -459,6 +474,18 @@ SwingUtilities.invokeLater(() -> { txtDataView.append(finalText); txtDataView.append("\n"); + + // 检查并限制行数 + int lineCount = txtDataView.getLineCount(); + if (lineCount > MAX_LINES) { + try { + int end = txtDataView.getLineEndOffset(TRIM_LINES - 1); + txtDataView.replaceRange("", 0, end); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + txtDataView.setCaretPosition(txtDataView.getDocument().getLength()); }); -- Gitblit v1.9.3