I'm using netbeans graphic intarface to create my own JPanel.
But I have a problem.
When I change panel's layout in grid one I can only place cells on left and right side only of others. So instead of 2x2 I can only make 4x1.

Do you know what shoyd I do to make it working ?

Recommended Answers

All 3 Replies

Yes. If you have a GridLayout for your JPanel, and you want to change it so that it can display 2x2, you can use the GridLayout class methods to set it that way.

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/GridLayout.html

Look at the setColumns method and the setRows method. If you don't currently have the JPanel set to a GridLayout but you want it to be, then you'd have to use panel.setLayout(new GridLayout(2,2));

But how can i set number of rows in NB interface

I don't really remember. You don't have to specify it through the interface builder tool though, you can simply edit the code itself. On the left you should have some sort of list that indicates what component you are currently highlighting - all you'd need to do is figure out what the name of your JPanel is, by looking through the variable declarations netbeans has done for you (in the code) and then use panel.setColumns and panel.setRows. I have a new computer now, and haven't downloaded netbeans, otherwise I'd tell you how to do it with the interface builder itself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.