Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Grid layout

Started by The C modest god Apr 8, 2006 at 1:03 PM 1 replies 450+ views
Original Post
The C modest god
The C modest god
I want to create a window interface that will look like this:

----------------
|   Table      |
|              |
----------------
| B1 | B2 | B3 |
----------------
I thought doing this with two GridLayout, one will be add as a component of the other. But gridLayout is not a component, so I cant do this. How can I accomplish this sort of griding of the window? Thanks in advance.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
Nik02
Nik02
If you're using .net 2.0, I recommend using the TableLayoutPanel control for the general layout.

It adds RowSpan and ColSpan properties to it's child controls, so you can position the contained stuff across multiple cells like in HTML.
Niko Suni
The C modest god
The C modest god
Ok, I have solved this.
I simply created another JPanel and added it to the main GridLayout, and set the sub panel to have a gridLayout as well.

I have a problem with the buttons and the JTableHeader.
They both appear very tall, how do I change their height?
Here is the code:
            super.setLayout(new GridLayout (3, 1));            ButtonsPanel.setLayout(new GridLayout (1, 3));            initUsersTable();            JTableHeader tableHed;            tableHed = m_table.getTableHeader();             tableHed.reshape(tableHed.getX(),                                              tableHed.getY(),                                             tableHed.getWidth(),                                             20);            super.add(tableHed);            super.add(m_table);            super.add(ButtonsPanel);            ButtonsPanel.add(new JButton("Add"));            ButtonsPanel.add(new JButton("Remove"));            ButtonsPanel.add(new JButton("Edit"));            m_window = new JFrame("Administrator");            m_window.getContentPane().add(this);            // TODO: Change on exit! write file!            m_window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);            m_window.pack();            m_window.setVisible(true);        }        private JComponent initUsersTable ()        {            String[] colNames = {"Name", "Password", "Type"};            String[][] data=null;            String[] KeysList;                        KeysList = m_userDatabase.GetKeysList();            KeysList = new String[10];            data = new String[KeysList.length][3];            for (int i=0; i<KeysList.length; i++)            {                data[0] = KeysList;                data[1] = KeysList;                data[2] = KeysList;            }            m_table = new JTable(data, colNames);                        return m_table;        }


I have another question.
I have a map object.
I entered objects to the map with the key being a string.
I want to get a String[] array containing all the keys in the map.
How would I do that?
I tried this:
        public String[] GetKeysList()        {            HashSet KeySet = null;                        KeySet = (HashSet)m_usersList.keySet();            return (String[])KeySet.toArray();                    }

But I got runtime error on: KeySet = (HashSet)m_usersList.keySet();

[Edited by - The C modest god on April 8, 2006 2:33:06 PM]
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.