Gaming Java issues - changing sizes of components

Skyline969

MENUdo Afficionado
OP
Member
Joined
Nov 18, 2008
Messages
2,209
Trophies
0
Age
32
Location
Saskatchewan
Website
Visit site
XP
518
Country
Canada
Ok, well I've got a JFrame, and in that frame a JTextArea, a JList, a JTextField, and a JButton. The JTextArea is in its own panel with an EmptyBorder (for spacing), the JList is in its own panel with an EmptyBorder (to make some spacing between the JTextArea and JList), and the JTextField and JButton are in their own panel with an EmptyBorder and FlowLayout.
The JTextArea is at CENTER, the JList is at EAST, and the JTextField and JButton are at SOUTH.
The JTextArea and JList's EmptyBorders have the same top and bottom attributes.

My problem is this:
No matter what I do (setPreferredSize, etc), I can't get the JTextArea and JList to have the same height! It's not so noticeable on Windows, but on Linux it is. What can I change so the JTextArea and JList have the exact same height?

Btw, it's a chat program I'm making, sort of a one-room IRC essentially. More or less it's for my classmates and I to use at school, but it's also my little project to keep me sane during the intense amount of work I have going on.

If someone could give me a little help, I'd appreciate it.

EDIT: Screenshots of the difference. Note the spacing between the JTextArea and the JTextField as opposed to the JList and JTextField (or JButton, as it's overtop that).

Windows:
2n1s7xh.jpg


Linux:
jg732t.png
 

Psyfira

Credit: 0ml. Insert tea to continue
Member
Joined
Dec 31, 2003
Messages
3,886
Trophies
0
Location
England
XP
270
Country
It's been a really long time since I used this stuff so forgive me if I'm way off the mark, but here's a link to Sun's Java tutorial page on Swing layouts and solving layout issues: http://java.sun.com/docs/books/tutorial/ui...t/problems.html

Specifically:
QUOTE said:
No matter how you specify your component's size, be sure that your component's container uses a layout manager that respects the requested size of the component
Maybe do a bit of reading in there to check the different layout options Swing offers and their properties to see if the one you're using is the right one for the job?

Apologies for the vague-ness, it's been a while :S
 

Skyline969

MENUdo Afficionado
OP
Member
Joined
Nov 18, 2008
Messages
2,209
Trophies
0
Age
32
Location
Saskatchewan
Website
Visit site
XP
518
Country
Canada
Unfortunately Psyfira, I've been up and down those tutorials and couldn't find something. I'm taking a couple classes in college (88'd my beginner one, currently 86 on my intermediate one) about Java, and I've looked at tutorials, but I can't seem to fix the problem no matter what I do.
 

Skyline969

MENUdo Afficionado
OP
Member
Joined
Nov 18, 2008
Messages
2,209
Trophies
0
Age
32
Location
Saskatchewan
Website
Visit site
XP
518
Country
Canada
tj_cool said:
Maybe you should give both the same font and make them have an equal amount of rows
Or is that like that already?

edit: is it something like this you want?
IRC_test.png


If so, here's the source: http://pastie.org/919052 (made with GridBagLayout)
That's exactly what I want. I've never used GridBagLayout in my courses, so I didn't use it now. However, I did fix the problem by placing the JTextArea and the JList in one single JPanel, then setting it to use... I forget which layout, but wasn't GridBagLayout... possibly FlowLayout or GridLayout. Anyways, after that was said and done, I used setPreferredSize and tweaked the widths a little. Works fine after that. My project continues!

EDIT: Of course, mine's different in terms of sending. It first checks if the message is a command (IRC uses /, I use ./). If it's not, then it sends the message to the server. The server then sends the message to all clients connected. If the message IS a command, it executes the command which places text in the JTextArea. Either way, after that it does set the JTextField's text to "".

Another thing I did was override the paintComponent of the JTextField, so although it's a 2 row tall field, the cursor is in the top left of the field instead of in the center like as you can see in your screenshot.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    BigOnYa @ BigOnYa: https://youtu.be/heNQ-22Mqnk?si=B4bTa9MKZkRNCkxU