I need to set up a visible GridBagLayout with 2 JListboxes

GridBAgLayout should be 100 by 100 = 1000 cells.
The two Jlist boxes should be placed to-from X,Y cell starting from 0,0 which would be upper,left side.

Is this approach possible?

--
Idar
IdarhillgaarAsked:
Who is Participating?
 
RomanRegaConnect With a Mentor Commented:
Maybe i get what you mean.

You mean you want divide the space in tiles and then say (x,y) are "tile coords" of the upper left corner
and then width and height to say how many tiles you wish the JList to be large and tall.

I dont know if that's the best approach to the problem, but the answer is yes. It can be done.

I have not time to test this now. But i hope it can help you.

Try like this:

JPanel pane = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints( x, y, width, height, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,new Insets(0, 0, 0, 0), 0 ,0 );
pane.add(YOURJLIST, c);

Try obviosly changing the GridBagConstraints params as you wish.
For detailed explaination look:
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/GridBagConstraints.html

 
0
 
RomanRegaCommented:
i dont think i quite get what you mean.
Can you clarify it a little.
0
 
aozarovCommented:
If your cells are equal then you might want to consider GridLayout instead.
Having 1000 cells might look weird though.
You can't have the same component appear in more then once Cell.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
IdarhillgaarAuthor Commented:
I want to set up a JPane with cells, then place components around inside these cells like a coordinate system.
0
 
IdarhillgaarAuthor Commented:
I suppose 1000 cells are too much. - cell numbers can be changed though.
0
 
aozarovCommented:
As I said if you plan to have a Grid layout style then you might consider GridLayout(x,y) instead.
0
 
IdarhillgaarAuthor Commented:
Cheers,

U mentioned it might not be the best approach? I'd very much like to know a better approach if u have one.

Thanks so far though :)
0
 
RomanRegaCommented:
It depends on what is your final purpose.

Try this one. If you get exacly what you want, without any performance problem... what the hell... that's your choice.

Otherwise you can always program yourself a custom layout.
Can be useful because you can use it in other projects too.
And, if you get the job right, you get exacly what you want.

GridBaglayout has the worst reputation due to its  GridBagConstraints monster. But that doesn't mean that sucks or it is useless. Give it a try and report any problem.

Sorry if i didnt answer before, but here is Italy, and time is different :)
0
 
IdarhillgaarAuthor Commented:
Cheers!

Chosed to scrap the GridBag - was too awkward to work with and I don't have the time.

Sorry I didn't reply earlier, really busy in my final year :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.