Path: blob/master/test/jdk/javax/swing/JTable/LostTextTest.java
41152 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*/22/*23* @test24* @bug 815906825* @summary Verifies if Jtable rendering is ok.26* @run main/manual LostTextTest27*/28import java.awt.BorderLayout;29import java.awt.Component;30import java.awt.FlowLayout;31import java.util.concurrent.CountDownLatch;32import java.util.concurrent.TimeUnit;33import javax.swing.JButton;34import javax.swing.JDialog;35import javax.swing.JFrame;36import javax.swing.JPanel;37import javax.swing.JTable;38import javax.swing.JTextArea;39import javax.swing.SwingUtilities;40import javax.swing.table.DefaultTableModel;41import javax.swing.table.TableModel;4243public class LostTextTest {4445static DefaultTableModel model;4647public static void main(String[] args) throws Exception {48final CountDownLatch latch = new CountDownLatch(1);4950LostText test = new LostText(latch);51Thread T1 = new Thread(test);52T1.start();5354// wait for latch to complete55boolean ret = false;56try {57ret = latch.await(30, TimeUnit.SECONDS);58} catch (InterruptedException ie) {59throw ie;60}61if (!ret) {62test.dispose();63throw new RuntimeException(" User has not executed the test");64}6566if (test.testResult == false) {67throw new RuntimeException("Some text were not rendered properly"68+ " during painting of Jtable rows ");69}70}71}7273class LostText implements Runnable {74static JFrame f;75static JDialog dialog;76static DefaultTableModel model;77public boolean testResult = false;78private final CountDownLatch latch;7980public LostText(CountDownLatch latch) throws Exception {81this.latch = latch;82}8384@Override85public void run() {86try {87createUI();88lostTextTest();89} catch (Exception ex) {90if (f != null) {91f.dispose();92}93latch.countDown();94throw new RuntimeException("createUI Failed: " + ex.getMessage());95}9697}9899public void dispose() {100dialog.dispose();101f.dispose();102}103104private static void lostTextTest() throws Exception {105SwingUtilities.invokeAndWait(new Runnable() {106@Override107public void run() {108f = new JFrame();109f.add(getComp());110f.setSize(300, 300);111f.setLocationRelativeTo(null);112f.setVisible(true);113}114115private Component getComp() {116JTable jTable = new JTable(testSelectionWithFilterTable());117return jTable;118}119});120}121122private static TableModel testSelectionWithFilterTable() {123model = new DefaultTableModel(0, 1);124int last = 10;125for (int i = 0; i <= last; i++) {126model.addRow(new Object[]{i});127}128return model;129}130131private final void createUI() throws Exception {132SwingUtilities.invokeAndWait(new Runnable() {133@Override134public void run() {135136String description137= " INSTRUCTIONS:\n"138+ " A JTable will be shown.\n"139+ " Try to select different rows via mouse or keyboard.\n "140+ " Please verify if text are painted properly.\n"141+ " If any moment any part of the rows will not be\n "142+ " painted properly and if some text are missing in JTable,\n "143+ " then press fail else press pass";144145dialog = new JDialog();146dialog.setTitle("textselectionTest");147JTextArea textArea = new JTextArea(description);148textArea.setEditable(false);149final JButton passButton = new JButton("PASS");150passButton.addActionListener((e) -> {151testResult = true;152dispose();153latch.countDown();154});155final JButton failButton = new JButton("FAIL");156failButton.addActionListener((e) -> {157testResult = false;158dispose();159latch.countDown();160});161JPanel mainPanel = new JPanel(new BorderLayout());162mainPanel.add(textArea, BorderLayout.CENTER);163JPanel buttonPanel = new JPanel(new FlowLayout());164buttonPanel.add(passButton);165buttonPanel.add(failButton);166mainPanel.add(buttonPanel, BorderLayout.SOUTH);167dialog.add(mainPanel);168dialog.pack();169dialog.setVisible(true);170}171});172}173}174175176