You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by vl...@apache.org on 2020/03/16 15:13:11 UTC
[jmeter] branch master updated: Extract JTextAreaWithBorder
component
This is an automated email from the ASF dual-hosted git repository.
vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git
The following commit(s) were added to refs/heads/master by this push:
new c06f048 Extract JTextAreaWithBorder component
c06f048 is described below
commit c06f048a26312d394eba5585134890bdf6c7243d
Author: Vladimir Sitnikov <si...@gmail.com>
AuthorDate: Mon Mar 16 18:10:30 2020 +0300
Extract JTextAreaWithBorder component
It fixes border disappearing when look and feel is changed.
---
.../jmeter/gui/AbstractJMeterGuiComponent.java | 7 ++---
.../java/org/apache/jmeter/gui/CommentPanel.java | 9 ++----
.../apache/jorphan/gui/JTextAreaWithBorder.java | 34 ++++++++++++++++++++++
3 files changed, 38 insertions(+), 12 deletions(-)
diff --git a/src/core/src/main/java/org/apache/jmeter/gui/AbstractJMeterGuiComponent.java b/src/core/src/main/java/org/apache/jmeter/gui/AbstractJMeterGuiComponent.java
index c562b09..b7dedcb 100644
--- a/src/core/src/main/java/org/apache/jmeter/gui/AbstractJMeterGuiComponent.java
+++ b/src/core/src/main/java/org/apache/jmeter/gui/AbstractJMeterGuiComponent.java
@@ -41,6 +41,7 @@ import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.property.StringProperty;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.visualizers.Printable;
+import org.apache.jorphan.gui.JTextAreaWithBorder;
import org.apiguardian.api.API;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -81,7 +82,7 @@ public abstract class AbstractJMeterGuiComponent extends JPanel implements JMete
@SuppressWarnings("DeprecatedIsStillUsed")
protected NamePanel namePanel;
- private final JTextArea commentField = new JTextArea();
+ private final JTextArea commentField = new JTextAreaWithBorder();
/**
* When constructing a new component, this takes care of basic tasks like
@@ -229,10 +230,6 @@ public abstract class AbstractJMeterGuiComponent extends JPanel implements JMete
private void init() {
initGui();
- // JTextArea does not have border by default (see https://bugs.openjdk.java.net/browse/JDK-4139076)
- // However we want it to look like a text field. So we borrow a border from there
- Border border = new JTextField().getBorder();
- commentField.setBorder(border);
}
/**
diff --git a/src/core/src/main/java/org/apache/jmeter/gui/CommentPanel.java b/src/core/src/main/java/org/apache/jmeter/gui/CommentPanel.java
index 341c927..06b3103 100644
--- a/src/core/src/main/java/org/apache/jmeter/gui/CommentPanel.java
+++ b/src/core/src/main/java/org/apache/jmeter/gui/CommentPanel.java
@@ -24,10 +24,9 @@ import java.awt.BorderLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
-import javax.swing.JTextField;
-import javax.swing.border.Border;
import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.gui.JTextAreaWithBorder;
import org.apiguardian.api.API;
/**
@@ -55,13 +54,9 @@ public class CommentPanel extends JPanel {
private void init() { // WARNING: called from ctor so must not be overridden (i.e. must be private or final)
setLayout(new BorderLayout(5, 0));
- commentField = new JTextArea();
+ commentField = new JTextAreaWithBorder();
JLabel commentLabel = new JLabel(JMeterUtils.getResString("testplan_comments")); //$NON-NLS-1$
commentLabel.setLabelFor(commentField);
- // JTextArea does not have border by default (see https://bugs.openjdk.java.net/browse/JDK-4139076)
- // However we want it to look like a text field. So we borrow a border from there
- Border border = new JTextField().getBorder();
- commentField.setBorder(border);
commentLabel.setVerticalAlignment(JLabel.TOP);
add(commentLabel, BorderLayout.WEST);
add(commentField, BorderLayout.CENTER);
diff --git a/src/jorphan/src/main/java/org/apache/jorphan/gui/JTextAreaWithBorder.java b/src/jorphan/src/main/java/org/apache/jorphan/gui/JTextAreaWithBorder.java
new file mode 100644
index 0000000..551c58c
--- /dev/null
+++ b/src/jorphan/src/main/java/org/apache/jorphan/gui/JTextAreaWithBorder.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jorphan.gui;
+
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+
+/**
+ * Creates a text area with a border that looks like {@link JTextField}.
+ */
+public class JTextAreaWithBorder extends JTextArea {
+ @Override
+ public void updateUI() {
+ super.updateUI();
+ // JTextArea does not have border by default (see https://bugs.openjdk.java.net/browse/JDK-4139076)
+ // However we want it to look like a text field. So we borrow a border from there
+ setBorder(new JTextField().getBorder());
+ }
+}