如何将不可编辑的文本视图添加到JDialog?

时间:2018-09-29 11:11:05

标签: java string textview jdialog

我有一个带有标记为“ order”的按钮的JFrame。单击该按钮后,将出现一个对话框。该对话框应该显示按文本视图排序的项目的摘要。我想到了使用字符串作为查看订单的一种方式,但是那行不通...

 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;
 import java.awt.FlowLayout;
 import java.awt.event.ActionEvent;
 import javax.swing.SwingUtilities;
 import javax.swing.JRadioButton;

 public class PizzaOrder3 {

 PizzaOrder3() {

  JFrame frame = new  JFrame();

  JButton order = new JButton("Order");
  JPanel panel1 = new JPanel();
  panel1.add(order);
  frame.getContentPane().add(panel1);
  panel1.setBounds(350,632,110,40);
  panel1.setOpaque(false);

  //Action listener for showing summary of the order
  order.addActionListener(new ActionListener()
{
  public void actionPerformed(ActionEvent e)
  {

    JDialog d = new JDialog(frame, "Hello", true);


    //Where the coding for text view is meant to go

    d.setSize(400, 300);
    d.setVisible(true);       
  }
});

    frame.setLayout(null);                              
    frame.setSize(600, 700);
    frame.getContentPane().setBackground(new Color(40, 80, 120));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
  }

  public static void main(String[] args) {

      PizzaOrder3 PizzaOrder3 = new PizzaOrder3();    
    }
  }

0 个答案:

没有答案