Java对话框 [英] Java Dialog Box

查看:106
本文介绍了Java对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何制作以下窗口:

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

我会用什么来格式化?类似于BorderLayout的东西?有更好的方法吗?

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

我尝试过使用JFrame,JPanel和JTextArea的组合;如下:

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.

编辑:我不是问如何用数据填充窗口 - 只是如何生成窗口。它似乎只有一个固定的大小(长度和宽度)和边框。好像它是一个准系统窗口。

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?

推荐答案

这是一个提案(它可以在很大程度上改进,但至少,你会有一个起点):

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);
}

这篇关于Java对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆