1

I'm working on a application which takes pizza orders. Once the user clicks the order summary button the program would display the order summary. The application looks like this: enter image description here

I would like to print out the order summary(only not the error) in a new penal with a JTextArea like such:

enter image description here

But I don't know how. This is what my application displays right now: enter image description here

Here is the Code related to the display:

        orderSummary = "Customer Name: " + name +
                       "\nPhone Number: " + phoneNumber +
                       "\nSize: " + size +
                       "\nToppings: " + toppings +
                       "\nTotal: $" + total;
        if(error) 
            JOptionPane.showMessageDialog(null, ErrorString);
        else
            JOptionPane.showMessageDialog(null, orderSummary);

Error display:

enter image description here

Zin Yackvaa
  • 835
  • 1
  • 7
  • 15
  • 1
    May be have a look at [How to Use CardLayout](http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html) and [How to Use Text Areas](http://docs.oracle.com/javase/tutorial/uiswing/components/textarea.html) – MadProgrammer Feb 15 '16 at 00:02
  • 1
    You also might consider using more of a "wizard" style approach, where the user is presented with only a single view at a time (with previous/next navigation), something like [this](http://stackoverflow.com/questions/31602113/listener-placement-adhering-to-the-traditional-non-mediator-mvc-pattern/31604919#31604919) or [this](http://stackoverflow.com/questions/23352226/singleton-with-cardlayout-wont-show-card-when-another-class-calls-singleton-ins/23352348#23352348) examples – MadProgrammer Feb 15 '16 at 00:05
  • Hi @MadProgrammer, how to I make this JPanel visible. OrderSummery = new JPanel(); JTextArea order = new JTextArea(); order.setText(orderSummary); OrderSummery.add(order); – Zin Yackvaa Feb 15 '16 at 00:11
  • You add it to something which is contained within a window – MadProgrammer Feb 15 '16 at 01:23

1 Answers1

2

I'm not 100% sure of what you are asking, but if you are looking for a dialog to popup (not just a panel), then you could try something like:

    JDialog zMessageDialog = new JDialog((java.awt.Frame) null, true);
    zMessageDialog.setTitle("Order summary");
    zMessageDialog.setLayout(new BorderLayout());
    JTextArea zTextArea = new JTextArea("Blah blah\nblah blah\nblah blah");
    zTextArea.setEditable(false);
    zTextArea.setColumns(40);
    zTextArea.setRows(10);
    zTextArea.setBackground(null);
    JScrollPane zScrollPane = new JScrollPane(zTextArea);
    zMessageDialog.add(zScrollPane, BorderLayout.CENTER);
    zMessageDialog.revalidate();
    zMessageDialog.pack();
    zMessageDialog.setVisible(true);

This just puts a JTextArea in a JDialog. It makes the JTextArea non-editable, and sets its background color to null (which makes it look less editable).

Of course, this may not be the best way to go in terms of a user interface, but that is a different question. If you are using an IDE like Netbeans, you can easily create a separate class based on JDialog and add a panel at the bottom with an "OK" button, and whatever other customizations you desire.

jlallen
  • 91
  • 5