-3

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?

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • The bottom part should be a jTable. – Paul Tomblin Aug 16 '12 at 17:33
  • you need to investigate how to use the various `LayoutManager`s to get what you want. a JTable would be good, but you could create your dialog by using `GridBagLayout` or other nested layouts – John Gardner Aug 16 '12 at 17:44
  • I think your Q's A is here: http://stackoverflow.com/questions/2405039/pop-up-window-in-java-swing – Zac Aug 16 '12 at 17:47
  • Thanks. I know if it was C++ I would #include at least to format the headings..Although the window is still a mystery. – user1513909 Aug 16 '12 at 17:49

3 Answers3

2

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);
}
aymeric
  • 3,877
  • 2
  • 28
  • 42
1

Start with a JDialog (as you've asked)

Take a look at JTable to format the content

Take a look at BorderLayout

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
1

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045