Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems adding two panels  RSS feed

 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope someone can help, java GUI tools are frusterating.

I have a JFrame, that will, hopefully, eventually look like a standard chat client. I have a JMenuBar and JToolbar already. I added in a JPanel, that has two Jpanels, on the left and right. What is happening is that the entire window is doubling or so, in size, and the text only shows up when the window is maximized. Even more troubling is that only one JPanel is visible, the first one created. It takes up the entire area of the base JPanel.

Can someone please point me in the right direction


[ July 11, 2006: Message edited by: Rusty Shackleford ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> new JTextArea(100,200);

they are big textAreas, not in a scrollpane with a preferredSize.

try making both
new JTextArea(10,20);

and see what happens

[EDIT]
forgot to add the scrollpane size
[ July 11, 2006: Message edited by: Michael Dunn ]
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, all my dumb questions seem to have simple solutions.

One more dumb question, how do I align the elements in leftPanel and rightPanel on the left side? With your changes they are right jusified. I tried this with no luck:

leftPanel.add(chatPane, BorderLayout.WEST);
[ July 11, 2006: Message edited by: Rusty Shackleford ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seems OK in this (win98SE java 1.4.0_01)

this is just the posted code (with the size change) and a main()

 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Weird, I ran your code and it displayed everything properly, except when it is maximized, it looks very similar to mine, at any size.

What mine looks like is the leftPanel JTextArea is right justified and the rightPanel, left justified. The test areas are not touching, but have a small space between them. If I comment out the Toolbar it works fine.

Here is the code that calls and adds Panel:


[ July 11, 2006: Message edited by: Rusty Shackleford ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note: I had changed the name of Panel to MyPanel (avoid conflict with java.awt.Panel)

I think this is what you're trying to do - split-screen

this is the MyPanel constructor
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, split screen. Both sides will have at least 2 components and they need to be placed vertically, and I figure using BoxLayout and 2 JPanels will be much easier then futzing with GrdBagLayout or SpringLayout.

Thanks alot for your help,it is greatly appreciated.

Am I correct in assuming that that the panels will resize to the largest component in each panel, and both panels will still fit? I have to add in a text tool bar and a window for typing text, and these may end up needing to be longer then the text area above it.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Am I correct in assuming that that the panels will resize to the largest component in each panel,

the GridLayout(1,2) will take up half each of its size/preferredSize, so if you add a wide component to one side, the other side will match the width.

perhaps a JSplitPane might be a better choice if you don't want exact halves.

when using BoxLayout.Y_AXIS, you will need to be aware of each component's
alignmentX - often you will need to setAlignmentX(..) to get the desired location
of the component.

the best thing to do is experiment.
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again, I will monkey around with it, until this stuff sinks in.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!