Java Dialog Box [closed]

夙愿已清 提交于 2019-11-28 13:03:20

问题


How would I produce the following window:

http://postimage.org/image/61aa8hrvb/

What would I use for formatting? Something similar to BorderLayout? Is there a better way?

I have tried using a combo of JFrame, JPanel and JTextArea; as follows:

 public static void doListAllChecks() {
    int transCount = CAObject.getTransCount();

    JFrame frame = new JFrame();
    frame.setVisible(true);
    JPanel content = new JPanel();
    for (int idx = 0; idx < transCount; idx++)
    {
        Transaction tObj = CAObject.getTrans(idx);
        if (tObj != null) {
            if (tObj.getTransId() == Constants.CHECK_ID)
            {
                System.out.println("Check ID " + tObj.getTransNumber() +
                        " Check Amount " + tObj.getTransAmount());
                JTextArea textArea = new JTextArea(5,20);
                textArea.setText("Check " + tObj.getTransAmount());
                content.add(textArea, BorderLayout.EAST);
            }
        }
    }

    frame.setContentPane(content);
    frame.setTitle("Dialog Display");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.pack();
}

I am looking to produce a basic and very simple style of a window. I have the data but I don't know how to produce the window.

Edit: I am not asking how to fill the window with data—just how to produce the window. It seems that it just has a fixed size (length and width) and a border. It seems like it is a barebones window.

Is there anything that you can think of the resembles this style of a window?


回答1:


Here is one proposal (it could be largely improved but at least, you'll have a startig point):

public static void main(String[] args) throws Exception {

    String[][] transactions = new String[][] { { "0", "Check", "50.00" }, { "1", "svc.chrg.", "0.15" } };

    JDialog f = new JDialog();
    JTable table = new JTable(transactions, new String[] { "Id", "Type", "Amount" });

    f.add(new JLabel("List all transactions:", JLabel.CENTER), BorderLayout.NORTH);
    f.add(new JScrollPane(table));
    f.setTitle("Dialog Display");

    table.setPreferredSize(new Dimension(table.getPreferredSize().width, table.getRowHeight()
            * transactions.length));

    f.pack();
    f.setSize(470, 120);
    f.setLocationRelativeTo(null); // Center on screen
    f.setVisible(true);
    f.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
}



回答2:


Start with a JDialog (as you've asked)

Take a look at JTable to format the content

Take a look at BorderLayout




回答3:


Is there anything that you can think of the resembles this style of a window?

You might try setUndecorated(true), seen here, and maybe add a one-pixel border.



来源:https://stackoverflow.com/questions/11992506/java-dialog-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!