1 package org.ozoneDB.adminGui.widget; 9 10 import java.awt.*; 11 import javax.swing.*; 12 13 18 public class MessageBox { 19 20 private static void show(Component parentComponent, String message, String title, int messageType) { 21 JOptionPane pane = new JOptionPane(message, messageType); 22 23 pane.setBackground(Color.WHITE); 24 setBgColor(pane.getComponents(), Color.WHITE); 25 26 JDialog dialog = pane.createDialog(parentComponent, title); 27 dialog.show(); 28 } 29 30 private static void setBgColor(Component[] cmps, Color bgColor) { 31 int numComponents = cmps.length; 32 for (int i = 0; i < numComponents; i++) { 33 Component c = cmps[i]; 34 if (c instanceof Container) { 35 setBgColor(((Container) c).getComponents(), bgColor); 36 } 37 c.setBackground(bgColor); 38 } 39 } 40 41 42 public static void show(String message) { 43 show(null, message, "Message", JOptionPane.PLAIN_MESSAGE); 44 } 45 46 47 public static void showError(String title, String message) { 48 show(null, message, title, JOptionPane.ERROR_MESSAGE); 49 } 50 51 52 public static void showInfo(String title, String message) { 53 show(null, message, title, JOptionPane.INFORMATION_MESSAGE); 54 } 55 56 57 public static void showWarning(String title, String message) { 58 show(null, message, title, JOptionPane.WARNING_MESSAGE); 59 } 60 61 } 62 | Popular Tags |