893N/A/*
2362N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
893N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
893N/A *
893N/A * This code is free software; you can redistribute it and/or modify it
893N/A * under the terms of the GNU General Public License version 2 only, as
893N/A * published by the Free Software Foundation.
893N/A *
893N/A * This code is distributed in the hope that it will be useful, but WITHOUT
893N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
893N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
893N/A * version 2 for more details (a copy is included in the LICENSE file that
893N/A * accompanied this code).
893N/A *
893N/A * You should have received a copy of the GNU General Public License version
893N/A * 2 along with this work; if not, write to the Free Software Foundation,
893N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
893N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
893N/A */
893N/A
893N/A/* @test
1319N/A @bug 7193219
893N/A @summary JComboBox serialization fails in JDK 1.7
893N/A @author Anton Litvinov
893N/A*/
893N/A
893N/Aimport java.io.*;
893N/A
893N/Aimport javax.swing.*;
893N/Aimport javax.swing.plaf.metal.*;
893N/A
893N/Apublic class bug7193219 {
893N/A private static byte[] serializeGUI() {
893N/A // Create and set up the window.
893N/A JFrame frame = new JFrame("Serialization");
893N/A JPanel mainPanel = new JPanel();
893N/A
893N/A /**
893N/A * If JComboBox is replaced with other component like JLabel
893N/A * The issue does not happen.
893N/A */
893N/A JComboBox status = new JComboBox();
893N/A status.addItem("123");
893N/A mainPanel.add(status);
893N/A frame.getContentPane().add(mainPanel);
893N/A frame.pack();
893N/A
893N/A try {
893N/A ByteArrayOutputStream baos = new ByteArrayOutputStream();
893N/A ObjectOutputStream oos = new ObjectOutputStream(baos);
893N/A oos.writeObject(mainPanel);
893N/A oos.flush();
893N/A frame.dispose();
893N/A return baos.toByteArray();
893N/A } catch (IOException ioe) {
893N/A throw new RuntimeException(ioe);
893N/A }
893N/A }
893N/A
893N/A private static void deserializeGUI(byte[] serializedData) {
893N/A try {
893N/A ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(serializedData));
893N/A JPanel mainPanel = (JPanel)ois.readObject();
893N/A JFrame frame = new JFrame("Deserialization");
893N/A frame.getContentPane().add(mainPanel);
893N/A frame.pack();
893N/A frame.dispose();
893N/A } catch (Exception e) {
893N/A throw new RuntimeException(e);
893N/A }
893N/A }
893N/A
1319N/A public static void main(String[] args) throws Exception {
893N/A UIManager.setLookAndFeel(new MetalLookAndFeel());
1319N/A SwingUtilities.invokeAndWait(new Runnable() {
893N/A @Override
1319N/A public void run() {
893N/A deserializeGUI(serializeGUI());
893N/A }
});
}
}