2

I am trying to do something like below in Java, but and I have tried a BorderLayout so far (for the upper panel).

enter image description here

The problem with that approach is that I cannot add in a "HELP" button. So, I am vying for the GridBagLayout. The problem with that approach is that I might have to either add a bunch of empty JLabels or just forget the whole upperPanel idea, and just add directly to the JFrame (which would be a cheaper process because I don't have to use a resource-heavy JPanel, but probably wouldn't look as good).

Would you advise against adding a bunch of empty JLabels?

Java Devil
  • 10,629
  • 7
  • 33
  • 48
Mike Warren
  • 3,796
  • 5
  • 47
  • 99
  • Are you using an IDE? or are you trying to setup your layout by code all by sourself? And what amount of "bunch" are we talking here? ^^ – luk2302 Jul 06 '13 at 23:38
  • I am using Eclipse, and yes, I am trying to setup the layout code "all by myself". According to the picture, I figured the top to require `O(8)` columns (because the table has that many). The `JLabel` with the instructions and the `JComboBox` should take up `O(3)`, while the button should take up 1. That leaves `O(5)` empty spots on the top that would have to be filled if I am to house this all in the `upperPanel`. – Mike Warren Jul 06 '13 at 23:44
  • Does eclipse not have a gui editor? I would recommend that, netbeans has one ;) Any why do you use O-Notation? ^^ Besides that, i sadly can´t help you. – luk2302 Jul 06 '13 at 23:47
  • I use O-Notation because my estimates are just that: estimates. Also, I didn't see a GUI Editor. //So it is just me, my brainpower, and if it gets really, REALLY messy, this forum... – Mike Warren Jul 06 '13 at 23:51
  • 1
    Hmm, no GUI is bad -.- sorry for poiting the O-Notation out, but i can´t stop myself because you are using it wrong: O(1) = O(3) = O(5) = O(8) = basically every number -> O(constant) don´t get you anywhere. – luk2302 Jul 06 '13 at 23:54
  • and the number of empty spaces for both of the rows of content (in the upper part of the frame) per row is 4, not 5. //I tried to correct that; it was a typo, but it wouldn't let me. Also, thanks for the heads-up. – Mike Warren Jul 06 '13 at 23:56
  • 1
    Consider using a BoxLayout for the overall layout and a GridBagLayout for just the top "box" the top 1/3. And no, adding JLabel's is not very expensive. – Hovercraft Full Of Eels Jul 07 '13 at 00:06
  • 1
    I don't understand yet what you want to do and what the problem is. The phrases like "... I cannot add in a Help button..." and "... vying for GridBagLayout..." and "...I might have to either add a bunch of empty JLabels..." just don't tell us what you're trying to do. Is the "click this button for more help" rectangle an example of a help button that you want? Does it interfere with some layout you already have? Is that where you want it and you don't know how to put it there? – arcy Jul 07 '13 at 01:52
  • 1
    *" because I don't have to use a resource-heavy `JPanel`"* Panels are not 'resource heavy'. – Andrew Thompson Jul 07 '13 at 01:55
  • I predicted that someone would bring this up in specific, but I was "lost in the code" and couldn't do anything about it. No, it isn't an extra button; it is simply a ToolTip for the "Help" button – Mike Warren Jul 07 '13 at 01:55
  • 1
    GridBagLayout has thus neat feature(?) where you can add multiple components to the same cell with different constraints ;) – MadProgrammer Jul 07 '13 at 01:58
  • 1
    Why was this question downvoted? It was a serious question that exhibited serious thought and serious effort. – Mike Warren Jul 07 '13 at 02:06

2 Answers2

3

Is adding empty JLabels an expensive process?

No, it is not.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
1

I also found this about Fillers (my reason for asking this simple question):http://docs.oracle.com/javase/7/docs/api/javax/swing/Box.Filler.html

Mike Warren
  • 3,796
  • 5
  • 47
  • 99
  • 3
    Or you can achieve the same behaviour by Nesting various Layouts as suggested by @AndrewThompson, in this [post](http://stackoverflow.com/a/5630271/1057230) – nIcE cOw Jul 07 '13 at 06:50