Jump to content

Gui organization

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
random guy

random guy

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
(attached are the source files, closable frame just allows for the window to close easier)

hey i have this code i am working on as a little tech demo for a class. it is just a preview of the sorts of things you could implement into a program to educate children. this is a simple question about adding fractions(i will add more backend functionality to allow different questions to be loaded). the user needs to enter the numerator in the first box and denominator in the second box.

it all works so far (i will add more functionality soon) but the gui window doesnt look exactly as i like or like it should.

the problem is i have two jtext widgets above a button and i cant get the jtext widgets (which are supposed to be one line vertically and one column) to be the right size even though i constructed them to be.

after some googleing i remembered that components will resize to meet the full size of the layout's cells. one way around this is to pack it in a temperary jpanel (i called it buffer) and then pack that into the layout instead.

that worked for the button, not the jtext areas. i dont use jtext areas a lot but i think that they should always be one row which makes this mulirow deal weird and i constructed it with 1 column. seems like they are taking the same width as the button, height is weird.

also the components arent lined up properly.

any suggestions.

Attached Files


Hey like something i said? Helped you out? Or you just like supporting the Random Guy?
add to my rep. its quick and easy and definitely wont steal your girlfriend.

#2
gszauer

gszauer

    Programmer

  • Members
  • PipPipPipPip
  • 113 posts
Yes, two solutions actually.
First, don't use a layout manager.
Conainer pannel = [JFrame].getContentPane();

pannel.setDefaultLayout(null);
And set each of the components size, and location manually
[Component].setSize(width, height);

[Component].setLocation(x, y);

Second, and this is probably best for you, make a custom Layout Manager
java.net: Custom Layouts

By the way, to anyone reading this....
My 100th Post!!! WOOT!!! Go ME! :D:cool:

~Aristotle said:

It is the mark of an educated mind to entertain a tought without accepting it
If my post was helpful, please help me build some rep Posted Image

#3
random guy

random guy

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
great, almost there. i resolved most of it by making the pane that holds the input fields an preferedsize layout.

just the answer field is too spaced out. i first tried fixing it by making everything in a 0x2 preferred size layout but ran into issues since some cells should be blank. recommendations?

congrats on 100th post too btw.

new code attached:

Attached Files


Hey like something i said? Helped you out? Or you just like supporting the Random Guy?
add to my rep. its quick and easy and definitely wont steal your girlfriend.

#4
gszauer

gszauer

    Programmer

  • Members
  • PipPipPipPip
  • 113 posts
Place the one that is too spaced out in a GridBag Layout
How to Use GridBagLayout (The Java™ Tutorials > Creating a GUI with JFC/Swing > Laying Out Components Within a Container)

~Aristotle said:

It is the mark of an educated mind to entertain a tought without accepting it
If my post was helpful, please help me build some rep Posted Image

#5
random guy

random guy

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
awesome! thanks a lot, it looks much better now. i wish i learned this a long time ago.
Hey like something i said? Helped you out? Or you just like supporting the Random Guy?
add to my rep. its quick and easy and definitely wont steal your girlfriend.