Skip to content

Commit 498252f

Browse files
committed
8340799: Add border inside instruction frame in PassFailJFrame
Backport-of: 520060f79a3cedb8f93e6bbd0e9b2823eaabf79a
1 parent d7c2775 commit 498252f

File tree

1 file changed

+47
-13
lines changed

1 file changed

+47
-13
lines changed

test/jdk/java/awt/regtesthelpers/PassFailJFrame.java

+47-13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.awt.AWTException;
2525
import java.awt.BorderLayout;
2626
import java.awt.Dimension;
27+
import java.awt.FlowLayout;
2728
import java.awt.Font;
2829
import java.awt.GraphicsConfiguration;
2930
import java.awt.GraphicsDevice;
@@ -69,6 +70,7 @@
6970
import javax.swing.JSplitPane;
7071
import javax.swing.JTextArea;
7172
import javax.swing.Timer;
73+
import javax.swing.border.Border;
7274
import javax.swing.text.JTextComponent;
7375
import javax.swing.text.html.HTMLEditorKit;
7476
import javax.swing.text.html.StyleSheet;
@@ -655,6 +657,8 @@ private static JComponent createInstructionUIPanel(String instructions,
655657
boolean addLogArea,
656658
int logAreaRows) {
657659
JPanel main = new JPanel(new BorderLayout());
660+
main.setBorder(createFrameBorder());
661+
658662
timeoutHandlerPanel = new TimeoutHandlerPanel(testTimeOut);
659663
main.add(timeoutHandlerPanel, BorderLayout.NORTH);
660664

@@ -664,7 +668,7 @@ private static JComponent createInstructionUIPanel(String instructions,
664668
text.setEditable(false);
665669

666670
JPanel textPanel = new JPanel(new BorderLayout());
667-
textPanel.setBorder(createEmptyBorder(4, 0, 0, 0));
671+
textPanel.setBorder(createEmptyBorder(GAP, 0, GAP, 0));
668672
textPanel.add(new JScrollPane(text), BorderLayout.CENTER);
669673

670674
main.add(textPanel, BorderLayout.CENTER);
@@ -681,7 +685,8 @@ private static JComponent createInstructionUIPanel(String instructions,
681685
timeoutHandlerPanel.stop();
682686
});
683687

684-
JPanel buttonsPanel = new JPanel();
688+
JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER,
689+
GAP, 0));
685690
buttonsPanel.add(btnPass);
686691
buttonsPanel.add(btnFail);
687692

@@ -692,10 +697,12 @@ private static JComponent createInstructionUIPanel(String instructions,
692697
if (addLogArea) {
693698
logArea = new JTextArea(logAreaRows, columns);
694699
logArea.setEditable(false);
700+
logArea.setBorder(createTextBorder());
695701

696702
Box buttonsLogPanel = Box.createVerticalBox();
697703

698704
buttonsLogPanel.add(buttonsPanel);
705+
buttonsLogPanel.add(Box.createVerticalStrut(GAP));
699706
buttonsLogPanel.add(new JScrollPane(logArea));
700707

701708
main.add(buttonsLogPanel, BorderLayout.SOUTH);
@@ -713,7 +720,7 @@ private static JTextComponent configurePlainText(String instructions,
713720
JTextArea text = new JTextArea(instructions, rows, columns);
714721
text.setLineWrap(true);
715722
text.setWrapStyleWord(true);
716-
text.setBorder(createEmptyBorder(4, 4, 4, 4));
723+
text.setBorder(createTextBorder());
717724
return text;
718725
}
719726

@@ -735,6 +742,29 @@ private static JTextComponent configureHTML(String instructions,
735742
return text;
736743
}
737744

745+
/** A default gap between components. */
746+
private static final int GAP = 4;
747+
748+
/**
749+
* Creates a default border for frames or dialogs.
750+
* It uses the default gap of {@value GAP}.
751+
*
752+
* @return the border for frames and dialogs
753+
*/
754+
private static Border createFrameBorder() {
755+
return createEmptyBorder(GAP, GAP, GAP, GAP);
756+
}
757+
758+
/**
759+
* Creates a border set to text area.
760+
* It uses the default gap of {@value GAP}.
761+
*
762+
* @return the border for text area
763+
*/
764+
private static Border createTextBorder() {
765+
return createEmptyBorder(GAP, GAP, GAP, GAP);
766+
}
767+
738768

739769
/**
740770
* Creates a test UI window.
@@ -1086,26 +1116,30 @@ public void awaitAndCheck() throws InterruptedException, InvocationTargetExcepti
10861116
* Requests the description of the test failure reason from the tester.
10871117
*/
10881118
private static void requestFailureReason() {
1089-
final JDialog dialog = new JDialog(frame, "Test Failure ", true);
1090-
dialog.setTitle("Failure reason");
1091-
JPanel jPanel = new JPanel(new BorderLayout());
1092-
JTextArea jTextArea = new JTextArea(5, 20);
1119+
final JDialog dialog = new JDialog(frame, "Failure reason", true);
1120+
1121+
JTextArea reason = new JTextArea(5, 20);
1122+
reason.setBorder(createTextBorder());
10931123

10941124
JButton okButton = new JButton("OK");
10951125
okButton.addActionListener((ae) -> {
1096-
String text = jTextArea.getText();
1126+
String text = reason.getText();
10971127
setFailureReason(FAILURE_REASON
10981128
+ (!text.isEmpty() ? text : EMPTY_REASON));
10991129
dialog.setVisible(false);
11001130
});
11011131

1102-
jPanel.add(new JScrollPane(jTextArea), BorderLayout.CENTER);
1103-
1104-
JPanel okayBtnPanel = new JPanel();
1132+
JPanel okayBtnPanel = new JPanel(new FlowLayout(FlowLayout.CENTER,
1133+
GAP, 0));
1134+
okayBtnPanel.setBorder(createEmptyBorder(GAP, 0, 0, 0));
11051135
okayBtnPanel.add(okButton);
11061136

1107-
jPanel.add(okayBtnPanel, BorderLayout.SOUTH);
1108-
dialog.add(jPanel);
1137+
JPanel main = new JPanel(new BorderLayout());
1138+
main.setBorder(createFrameBorder());
1139+
main.add(new JScrollPane(reason), BorderLayout.CENTER);
1140+
main.add(okayBtnPanel, BorderLayout.SOUTH);
1141+
1142+
dialog.add(main);
11091143
dialog.setLocationRelativeTo(frame);
11101144
dialog.pack();
11111145
dialog.setVisible(true);

0 commit comments

Comments
 (0)