Path: blob/master/test/jdk/javax/swing/JFormattedTextField/7070795/JFormattedTextFieldTest.java
41153 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 707079526* @summary High contrast colour scheme fails to be applied to JFormattedTextField27* @requires (os.family == "windows")28* @run main/manual JFormattedTextFieldTest29*/30import java.awt.GridBagConstraints;31import java.awt.GridBagLayout;32import java.awt.event.ActionEvent;33import java.awt.event.ActionListener;34import java.text.NumberFormat;35import javax.swing.JButton;36import javax.swing.JFormattedTextField;37import javax.swing.JFrame;38import javax.swing.JLabel;39import javax.swing.JPanel;40import javax.swing.JTextField;41import javax.swing.SwingUtilities;42import javax.swing.UIManager;4344public class JFormattedTextFieldTest implements ActionListener {4546private static GridBagLayout layout;47private static JPanel mainControlPanel;48private static JPanel resultButtonPanel;49private static JLabel instructionText;50private static JButton passButton;51private static JButton failButton;52private static JFrame mainFrame;5354public static void main(String[] args) throws Exception {55JFormattedTextFieldTest jFormattedTextFieldTest = new JFormattedTextFieldTest();56}5758public JFormattedTextFieldTest() throws Exception {59createUI();60}6162public final void createUI() throws Exception {6364UIManager.setLookAndFeel("com.sun.java.swing.plaf."65+ "windows.WindowsLookAndFeel");6667SwingUtilities.invokeAndWait(() -> {6869mainFrame = new JFrame("Window LAF JFormattedTextField Test");70layout = new GridBagLayout();71mainControlPanel = new JPanel(layout);72resultButtonPanel = new JPanel(layout);7374GridBagConstraints gbc = new GridBagConstraints();75String instructions76= "<html>INSTRUCTIONS:<br>"77+ "Set Windows Theme to HighContrast#1.<br><br>"78+ "(ControlPanel->Personalization->High Contrast#1)<br><br>"79+ "If TextFiled colors are same test"80+ " passes else failed.<br><br></html>";8182instructionText = new JLabel();83instructionText.setText(instructions);8485gbc.gridx = 0;86gbc.gridy = 0;87gbc.fill = GridBagConstraints.HORIZONTAL;88mainControlPanel.add(instructionText, gbc);8990passButton = new JButton("Pass");91passButton.setActionCommand("Pass");92passButton.addActionListener(JFormattedTextFieldTest.this);93failButton = new JButton("Fail");94failButton.setActionCommand("Fail");95failButton.addActionListener(JFormattedTextFieldTest.this);96gbc.gridx = 0;97gbc.gridy = 0;98resultButtonPanel.add(passButton, gbc);99gbc.gridx = 1;100gbc.gridy = 0;101resultButtonPanel.add(failButton, gbc);102gbc.gridx = 3;103gbc.gridy = 0;104resultButtonPanel.add(new JTextField("12345"), gbc);105106NumberFormat format = NumberFormat.getIntegerInstance();107format.setMaximumIntegerDigits(5);108JFormattedTextField formatted = new JFormattedTextField(format);109formatted.setText("67891");110gbc.gridx = 5;111gbc.gridy = 0;112resultButtonPanel.add(formatted, gbc);113gbc.gridx = 0;114gbc.gridy = 1;115mainControlPanel.add(resultButtonPanel, gbc);116117mainFrame.add(mainControlPanel);118mainFrame.setSize(400, 200);119mainFrame.setLocationRelativeTo(null);120mainFrame.setVisible(true);121});122}123124@Override125public void actionPerformed(ActionEvent evt) {126if (evt.getSource() instanceof JButton) {127JButton btn = (JButton) evt.getSource();128cleanUp();129switch (btn.getActionCommand()) {130case "Pass":131break;132case "Fail":133throw new AssertionError("User Clicked Fail!");134}135}136}137138private static void cleanUp() {139mainFrame.dispose();140}141142}143144145146