Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  About Java swing layout (noob question)  (Read 1427 times)
0 Members and 1 Guest are viewing this topic.
Offline alaslipknot
« Posted 2013-06-04 20:28:15 »

Hello,
since this topic is not related to game development i decided to post it here,
a friend asked me to develop a little application for him, he is opening a Driver's education "school" and this app will help him to manage his students information.
I almost did every "core" thing, the program works but in console only, but now am having many problem with GUI creation, yes i admit it, i didn't learn enough Java Swing when i started ... i just wanted to jump in games,
anyway,
what i manly want to accomplish is something similar to this (build with NetBean GUI editor)


but i don't want to work with netBean neither with a GUI editor, i start making some labels and i created the JTable too, but my main problem is how to place them in the wanted places ?? i tried to use borderLayouts and this is the result i get :


so the whole trouble is, how to create a new label in a "new line" ??


thank you  

Am trying ...
hoping that it works
Offline Sammidysam
« Reply #1 - Posted 2013-06-04 21:05:31 »

Can't you set the layout to being vertical rather than horizontal, considering it is horizontal by default?  Using BoxLayout would be good, and using the option BoxLayout.PAGE_AXIS for the second argument would be ideal.  Also, what you are trying accomplish doesn't seem like using BorderLayout is good for.  I believe you want 2 JPanels going left to right with a JTable in the left panel and the information in the right panel.
Offline quew8

JGO Coder


Medals: 23



« Reply #2 - Posted 2013-06-04 21:21:04 »

What have you got against GUI creators (the Netbeans one is called Matisse btw). GUI creation is tedious, that's why you skipped over it in the tutorials so why not let a machine do the work for you. As programmers that is kind of what we are all about. If you want to do everything the hard way then why not play a board game? It will take you 20 times of trial and error before you get a GUI right in basic coding and it then breaks apart as soon as you add anything.

Anyway, I always find the simplest way to do any layout of GUIs is to divide the components up into panels (JPanel) each with either a horizontal (BoxLayout with LINE_AXIS) or vertical (BoxLayout with PAGE_AXIS) layout. It takes time (see above) but tends to be quite robust and work well with resizing etc.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Nate

JGO Kernel


Medals: 128
Projects: 3
Exp: 14 years


Esoteric Software


« Reply #3 - Posted 2013-06-04 21:22:54 »

TableLayout supports Swing. Smiley
http://code.google.com/p/table-layout/

Online ags1

JGO Knight


Medals: 28
Projects: 2
Exp: 5 years


Make code not war!


« Reply #4 - Posted 2013-06-04 21:35:30 »

What have you got against GUI creators (the Netbeans one is called Matisse btw). GUI creation is tedious, that's why you skipped over it in the tutorials so why not let a machine do the work for you. As programmers that is kind of what we are all about. If you want to do everything the hard way then why not play a board game? It will take you 20 times of trial and error before you get a GUI right in basic coding and it then breaks apart as soon as you add anything.

Anyway, I always find the simplest way to do any layout of GUIs is to divide the components up into panels (JPanel) each with either a horizontal (BoxLayout with LINE_AXIS) or vertical (BoxLayout with PAGE_AXIS) layout. It takes time (see above) but tends to be quite robust and work well with resizing etc.

On the contrary, I never use visual GUI builders. I prefer to have some code that translates my model to the Swing layout which I have built myself so that I have complete control. I don't code each button and text area, but I do write the code that generates the GUI elements based on my layout rules and my model.

For a clean and efficient layout (that is consistent across all your screens) avoid GUI builder and write the code.

Offline alaslipknot
« Reply #5 - Posted 2013-06-05 00:26:17 »

thank you guys,
i used a JSplitPane and the result was just like i want it  Grin


now i should found how to add rows to the table using a JButton, you can help if you want  Roll Eyes

Am trying ...
hoping that it works
Offline KevinWorkman

JGO Knight


Medals: 21
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #6 - Posted 2013-06-05 18:14:40 »

I'll add another vote against GUI builders. They hide what's really going on, so it can be pretty hard to debug a problem or to tell a novice how to achieve a certain result. Plus the code they generate is hideous.

Do whatever you want, but IMHO (and the opinion of most other GUI developers I know), gui builders hurt more than they help, especially if you're a beginner with Swing.

Static Void Games - Play indie games, learn game programming, upload your own games!
Offline 65K
« Reply #7 - Posted 2013-06-05 18:49:38 »

I recommend JGoodies FormLayout.

Offline Nate

JGO Kernel


Medals: 128
Projects: 3
Exp: 14 years


Esoteric Software


« Reply #8 - Posted 2013-06-05 19:39:26 »

I recommend JGoodies FormLayout.
Emo

Offline gouessej

« In padded room »



TUER


« Reply #9 - Posted 2013-06-05 19:54:34 »

Please fix the spelling mistake, replace "Condidat" by "Candidat".

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline alaslipknot
« Reply #10 - Posted 2013-06-05 20:09:36 »

Please fix the spelling mistake, replace "Condidat" by "Candidat".

xD
done  Roll Eyes

Am trying ...
hoping that it works
Offline matheus23

JGO Wizard


Medals: 97
Projects: 3


You think about my Avatar right now!


« Reply #11 - Posted 2013-06-05 22:05:58 »


I recommend TableLayout. Seriously.
 Kiss

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline alaslipknot
« Reply #12 - Posted 2013-06-05 22:22:33 »


yup am going to try that, i really regret that i didn't take time to correctly learn SWING & AWT am really lost when it's time to deal with ActionListeners and more complicated stuff , so i decided to build this app as a "game"  Roll Eyes
am gonna use LibGdx to do that and tableLayout seems to be a nice solution,

Am trying ...
hoping that it works
Offline gouessej

« In padded room »



TUER


« Reply #13 - Posted 2013-06-05 23:37:50 »

Lol maybe you consider the candidates are ass holes, that's why you mixed the French word "con" (which means more or less "ass hole" in English) with the word "candidate"  Grin

Offline CodeHead

JGO Coder


Medals: 35


From rags to riches...to rags.


« Reply #14 - Posted 2013-06-06 04:25:13 »

yup am going to try that, i really regret that i didn't take time to correctly learn SWING & AWT am really lost when it's time to deal with ActionListeners and more complicated stuff , so i decided to build this app as a "game"  Roll Eyes
am gonna use LibGdx to do that and tableLayout seems to be a nice solution,

Advice from a new guy; use the right tool for the job. The default Swing controls may take a bit of getting used to working with, but they offer consistency to the end user of your application, and a lot of built in, well tested conveniences that would require quite a lot of code to implement from scratch. While learning anything new seems intimidating, when it comes to ActionListeners, if you can write a function, you can write a listener.  Cheesy

Looking at your desired interface, I would say the most challenging thing to implement would be a custom table model to manage the table data. When it comes down to it though, it's just ArrayList manipulations under the covers. The default table model is pretty useless/inefficient for doing anything other than displaying static data. If you're interested, I have some table models that I've written for my job including a result set bound model for DB queries that I can post along with a sample that I wrote for a colleague showing how to tie it all together (ActionListeners and all) if you like. Wink

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Offline KevinWorkman

JGO Knight


Medals: 21
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #15 - Posted 2013-06-06 04:30:56 »

I agree with CodeHead. And you should be pretty comfortable with standard GUI, 2D drawing, and stuff like data structures and event handling before diving into a library like libGDX. Just my 2 cents, but I think you'll regret rushing into unfamiliar territory before becoming more familiar with the basics.

Static Void Games - Play indie games, learn game programming, upload your own games!
Offline alaslipknot
« Reply #16 - Posted 2013-06-06 05:57:23 »

thank you for the advice, and yes that was a stupid decision  Tongue am working with swing again now and am having some good advance by searching for code examples and use them in my application, i know this is a very bad way to code a program but i need to finish it the fast as possible then i'll focus on serious learning .
and @CodeHead yes please that would be very helpful !!

thank you

Am trying ...
hoping that it works
Offline CodeHead

JGO Coder


Medals: 35


From rags to riches...to rags.


« Reply #17 - Posted 2013-06-06 11:18:31 »

Let's give this a shot. I apologize in advance for the inconsistent comments. I couldn't find the finalized version of my code at home, so I ended up rebuilding the table model code from a few different development snapshots I had. That being said, I tend not to write the most coherent comments at 4 in the morning. Smiley If you have any questions, I am more than happy to shed some light on the code.

RSTableModel: http://pastebin.java-gaming.org/69fc4069b50
This is the custom table model. It contains methods to let you manipulate the structure and values of the data associated with the table. It can seem a bit overwhelming at first, but I tried to avoid any "cleverness" in the implementation.

Main: http://pastebin.java-gaming.org/9fc461b9054
The main application form. Contains a lot of NetBeans generated boiler plate code. The important bits are in the initTableModel function and the three action listener callback functions; btnAddRowActionPerformed, btnDeleteRowActionPerformed, and tblDemoMouseClicked.

And here is what it looks like when it's all put together (running under OpenBox on an ArchLinux system):


One final note. I haven't attempted to make the table model thread safe. It wasn't needed in the context that it was developed for, and I have no compelling need to do so. It should be trivial to implement a ReentrantLock or similar synchronization methods if desired.

I hope this helps you some.  As mentioned before, if you have any questions I will try to answer them as best as I can. Cool

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Offline matheus23

JGO Wizard


Medals: 97
Projects: 3


You think about my Avatar right now!


« Reply #18 - Posted 2013-06-06 17:45:35 »

@CodeHead: Oh wow. Are you the guy from
RSyntaxTextArea
? If yes, awesome! Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline CodeHead

JGO Coder


Medals: 35


From rags to riches...to rags.


« Reply #19 - Posted 2013-06-06 20:06:26 »

@CodeHead: Oh wow. Are you the guy from
RSyntaxTextArea
? If yes, awesome! Smiley

That looks like a damn nice control. Cheesy Unfortunately, I can neither claim any affiliation with, nor any credit for that project. Being an applications developer for an international car manufacturer, my code is rarely seen/utilized beyond the walls of the company I work for. Sorry if I bumped the awesome level down a few notches.  Wink

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (15 views)
2014-04-15 18:08:23

BurntPizza (14 views)
2014-04-15 03:46:01

UprightPath (27 views)
2014-04-14 17:39:50

UprightPath (12 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (51 views)
2014-04-10 04:04:31

BurntPizza (110 views)
2014-04-08 23:06:04

tom_mai78101 (211 views)
2014-04-05 13:34:39

trollwarrior1 (179 views)
2014-04-04 12:06:45

CJLetsGame (185 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!