import javax.swing.*; public class FixedWidthLabel { public static void main(String[] srgs) { final String s = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu nulla urna. Donec sit amet risus nisl, a porta enim. Quisque luctus, ligula eu scelerisque gravida, tellus quam vestibulum urna, ut aliquet sapien purus sed erat. Pellentesque consequat vehicula magna, eu aliquam magna interdum porttitor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed sollicitudin sapien non leo tempus lobortis. Morbi semper auctor ipsum, a semper quam elementum a. Aliquam eget sem metus."; final String html1 = "<html><body style='width: "; final String html2 = "px'>"; Runnable r = new Runnable() { @Override public void run() { JOptionPane.showMessageDialog( null, new JLabel(html1 + "200" + html2 + s)); JOptionPane.showMessageDialog( null, new JLabel(html1 + "300" + html2 + s)); } }; SwingUtilities.invokeLater(r); } }
/** * Called when a pattern cannot be compiled or some other error occurs; resets gui to valid state. * Thread safe. * * @param txt Error message text (friendly text appropriate for users) * @param e The exception that caused the problem */ public void doError(final String txt, final Throwable e) { SwingUtilities.invokeLater(() -> { String extraData = e.getLocalizedMessage() != null ? e.getLocalizedMessage(): (e.getClass() != null) ? e.getClass().toString(): ""; JOptionPane.showMessageDialog(InputPanel.this, txt + '\n' + extraData, "Tregex Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); // send to stderr for debugging useProgressBar(false); updateFoundStats(null, 0, 0); }); }
import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JOptionPane; public class TestImages { // *** your image path will be different ***** private static final String IMG_PATH = "src/images/image01.jpg"; public static void main(String[] args) { try { BufferedImage img = ImageIO.read(new File(IMG_PATH)); ImageIcon icon = new ImageIcon(img); JLabel label = new JLabel(icon); JOptionPane.showMessageDialog(null, label); } catch (IOException e) { e.printStackTrace(); } } }
private JButton m_multiplyBtn = new JButton("Multiply"); private JButton m_clearBtn = new JButton("Clear"); JPanel content = new JPanel(); content.setLayout(new FlowLayout()); content.add(new JLabel("Input")); content.add(m_userInputTf); content.add(m_multiplyBtn); content.add(new JLabel("Total")); content.add(m_totalTf); content.add(m_clearBtn); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JOptionPane.showMessageDialog(this, errMessage); m_multiplyBtn.addActionListener(mal); m_clearBtn.addActionListener(cal);
final JPopupMenu popupMenu = new JPopupMenu(); JMenuItem deleteItem = new JMenuItem("Delete"); deleteItem.addActionListener(new ActionListener() { JOptionPane.showMessageDialog(frame, "Right-click performed on table and choose DELETE"); frame.add(new JScrollPane(table), BorderLayout.CENTER); frame.pack(); frame.setVisible(true); SwingUtilities.invokeLater(new Runnable() {
void generate () { final String name = ui.form.nameText.getText().trim(); if (name.length() == 0) { JOptionPane.showMessageDialog(this, "Please enter a project name."); return; JOptionPane.showMessageDialog(this, "Please enter a package name."); return; JOptionPane.showMessageDialog(this, "Invalid package name"); return; JOptionPane.showMessageDialog(this, "Please enter a game class name."); return; JOptionPane.showMessageDialog(this, "Please enter a destination directory."); return; JOptionPane.showMessageDialog(this, "Please enter your Android SDK's path"); return; .showMessageDialog(this, "Your Android SDK path doesn't contain an SDK! Please install the Android SDK, including all platforms and build tools!"); return; JOptionPane.showMessageDialog(this, "HTML sub-projects are not supported by the selected programming language."); ui.form.gwtCheckBox.setSelected(false); modules.remove(ProjectType.HTML);
if (Utils.getConfigBoolean("history.warn_before_delete", true)) { JPanel checkChoise = new JPanel(); checkChoise.setLayout(new FlowLayout()); JButton yesButton = new JButton("YES"); JButton noButton = new JButton("NO"); yesButton.setPreferredSize(new Dimension(70, 30)); noButton.setPreferredSize(new Dimension(70, 30)); JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("Are you sure?"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(checkChoise); frame.setSize(405, 70); JOptionPane.showMessageDialog(null, "There are no history entries to re-rip. Rip some albums first", "RipMe Error", JOptionPane.showMessageDialog(null, "No history entries have been 'Checked'\n" + "Check an entry by clicking the checkbox to the right of the URL or Right-click a URL to check/uncheck all items",
JTextField textField = new JTextField(10); JPanel panel = new JPanel(); panel.add(textField); JOptionPane.showMessageDialog(null, panel);
""; JPanel p = new JPanel( new BorderLayout() ); JOptionPane.showMessageDialog(null, s); SwingUtilities.invokeLater(r);
final JLabel label = new JLabel(); int timerDelay = 1000; new Timer(timerDelay , new ActionListener() { ((Timer)e.getSource()).stop(); Window win = SwingUtilities.getWindowAncestor(label); win.setVisible(false); JOptionPane.showMessageDialog(null, label); SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGui();
public void run() { try{ JFrame frame = new JFrame("Web Browser"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.getContentPane().add(new WebBrowserPanel(url, usernameID, passwordID, username, password), BorderLayout.CENTER); frame.setSize(800, 600); frame.setLocationByPlatform(true); frame.setVisible(true); }catch(Exception e){ JOptionPane.showMessageDialog(null, "Cannot connect to the ripple site. URL - "+url); e.printStackTrace(); } } });
String param = getParameter("param"); System.out.println("parameter: " + param); add(new JLabel(param)); pa.start(); pa.setPreferredSize(new java.awt.Dimension(200,200)); JOptionPane.showMessageDialog(null, pa);
import java.awt.*; import javax.swing.*; class ColoredButton { public static void main(String[] args) { Runnable r = new Runnable() { @Override public void run() { try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } JButton b1 = new JButton("Button 1"); b1.setBackground(Color.RED); // these next two lines do the magic.. b1.setContentAreaFilled(false); b1.setOpaque(true); JOptionPane.showMessageDialog(null, b1); } }; SwingUtilities.invokeLater(r); } }
import java.awt.event.*; import javax.swing.*; class PopUpMenuDemo { public static void main(String[] args) { Runnable r = new Runnable() { public void run() { final JButton b = new JButton("Pop Up"); final JPopupMenu menu = new JPopupMenu("Menu"); menu.add("A"); menu.add("B"); menu.add("C"); b.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { menu.show(b, b.getWidth()/2, b.getHeight()/2); } } ); JOptionPane.showMessageDialog(null,b); } }; SwingUtilities.invokeLater(r); } }
import javax.swing.*; import java.awt.*; public class MainClass extends JFrame{ private JButton chooseFile; public MainClass(){// Constructor super("Your Title"); chooseFile = new JButton("Choose File"); HandlerClass handler = new HandlerClass(); chooseFile.addActionListener(handler); } private class HandlerClass implements ActionListener { public void actionPerformed(ActionEvent event) { JOptionPane.showMessageDialog(null,"Button has been clicked"); } } }
add(jScrollPane1); @Override public void run() { JOptionPane.showMessageDialog(null, new FileDragList()); SwingUtilities.invokeLater(r);
} catch (NoClassDefFoundError e) { LOG.info("Missing classes for XML parser", e); JOptionPane.showMessageDialog( this, "XML parser not in classpath - unable to load XML events.", } catch (Exception e) { LOG.info("Unable to create the action to load XML files", e); JOptionPane.showMessageDialog( this, "Unable to create a XML parser - unable to load XML events.", getContentPane().add(cp, BorderLayout.NORTH); getContentPane().add(jsp, BorderLayout.CENTER);
String ucText = typedText.toUpperCase(); if (magicWord.equals(ucText)) { JOptionPane.showMessageDialog(this, "Correct answer given"); exit(); } else { JOptionPane.showMessageDialog(this, "Sorry, \"" + typedText + "\" " + "isn't a valid response.\n" JOptionPane.showMessageDialog(this, "It's OK. " + "We won't force you to type " + magicWord + "."); SwingUtilities.invokeLater(new Runnable() { @Override public void run() {
JPanel gui = new JPanel(new BorderLayout()); final JPanel container = new JPanel(new BorderLayout()); gui.add(container, BorderLayout.CENTER); container.add(tb, BorderLayout.NORTH); for (int ii=0; ii<3; ii++) { tb.add(new JButton("Button")); enable.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent ae) { gui.add(enable, BorderLayout.SOUTH); JOptionPane.showMessageDialog(null, gui); SwingUtilities.invokeLater(new Runnable(){ @Override public void run() {
JOptionPane.showMessageDialog(c, "Bye Bye!"); SwingUtilities.invokeLater(new Runnable() { public void run() { f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); f.addWindowListener( new WindowAdapter() { @Override f.setSize(300,200); f.setLocationByPlatform(true); f.setVisible(true);