• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to program specific simple gui

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I program this GUI?



This is what I came up so far:
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Losty wrote:This is what I came up so far:...


And your question is?

I'm afraid "How do I program this GUI?" is a bit vague. We don't supply answers; we help you to find your own.

So:
  • Have you compiled it?
  • Have you run it?
  • What happens when you do?

  • Winston
     
    John Losty
    Ranch Hand
    Posts: 128
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    We don't supply answers;



    Where can I get complete answer?
     
    Winston Gutkowski
    Bartender
    Posts: 10780
    71
    Hibernate Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    John Losty wrote:Where can I get complete answer?


    You could try here. They seem to be happier to hand out "ready-made" answers than we are; and they have some very knowledgeable people.

    But even there you might get snippy replies if they think you simply want someone else to do your work for you.

    We're happy to help here too; but we won't simply provide answers. Have a look at our HowToAskQuestionsOnJavaRanch (←click→) and NotACodeMill pages for more information.

    Winston
     
    John Losty
    Ranch Hand
    Posts: 128
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    But even there you might get snippy replies if they think you simply want someone else to do your work for you.



    I don't want nobody to do the work for me, I just want to learn as quickly as possible how to do this (kind of) GUI program.
     
    Winston Gutkowski
    Bartender
    Posts: 10780
    71
    Hibernate Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    John Losty wrote:I don't want nobody to do the work for me, I just want to learn as quickly as possible how to do this (kind of) GUI program.


    Well, you already appear to have written quite a bit. What problems are you running into?

    Winston
     
    John Losty
    Ranch Hand
    Posts: 128
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The problem is I know how to make simple gui programs but this one is a bit more complex.
    I don't have an idea how to create this gui. First I thouhgt I could create 3 Jpanels(FlowLayout arrangement) and that each has a grid layout with 2 x 1 elemetns inside. But it seems that doesn't work as you see in my example?
    If you know tell me a pseduo code agorithm?
     
    Winston Gutkowski
    Bartender
    Posts: 10780
    71
    Hibernate Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    John Losty wrote:The problem is I know how to make simple gui programs but this one is a bit more complex.
    I don't have an idea how to create this gui. First I thouhgt I could create 3 Jpanels(FlowLayout arrangement) and that each has a grid layout with 2 x 1 elements inside. But it seems that doesn't work as you see in my example?
    If you know tell me a pseduo code agorithm?


    Well, first off, I know very little about GUIs myself (hate them ), so I'm probably the wrong person to be asking; but from what I see, you appear to have, yes, 3 "parts" to your screen, each of which is "columnar" (ie, the components go from top to bottom):

    1st part - Contains either two checkboxes or one radio button (depending on whether both can be checked or not).

    2nd part - Contains two text boxes (8) with labels ("X: ") to the left. Now I'm not sure if Java has a component that contains both of those things (I seem to remember it didn't when I was playing around with GUIs, but that was a long time ago), so you may have to make up your own TextBoxWithLabel component.

    3rd part - Contains three buttons.

    So, if you're using GridLayout, I'd say that the dimensions are 2 x 1 (or 1 x 1), 2 x 1, and 3 x 1, and they'd get put in a panel with a 1 x 3 layout.

    However, there may well be much easier ways of doing it. I hear that BoxLayout, for example, is quite easy to use; but it may not be applicable here.

    HIH, and good luck.

    Winston
     
    Sheriff
    Posts: 7125
    184
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I'm going to move this into the Swing forum; it may get better "traction" there.
     
    John Losty
    Ranch Hand
    Posts: 128
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    This is how I did it:

    How can I further improve this becuase it is not exactly the same as in the 1st post

    and also why does look-and-feel of this widow is different from the one in the first post?
    I copied swing.properties file(inside file: "swing.defaultlaf=com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel") into and



    How can I further improve this becuase it is not exactly the same as in the 1st post?
     
    Bartender
    Posts: 5465
    212
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    hi John,

    First of all: a very easy way is to use a GUI builder, that
    comes with every IDE.

    If that is, for whatever reason, not acceptable:

    As you see, some Layoutmanagers have a sometimes
    unpleasant behaviour of making all components equal in
    size. So, a possible strategy is to use additional "dummy"
    objects, as to give all sub panels a similar look.

    Here is an example of what I mean. In the checkboxpanel
    I use 10 objects, of which 8 are dummy invisible JLabels.
    This is to give the other panels some guiding as to where
    their components should come.

    Well, it is a lot of code and it is certainly not the only way,
    but it is a reasonabl easy one. You could also have a look
    at SpringLayout, GridBagLayout and MigLayout (never used
    that one myself, but I heard quite good comments about it.

    By the way: since I make exclusive use of Layoutmanagers,
    I also issue 'simpleFrame.pack();' to let these managers determine
    the sizes.
     
    John Losty
    Ranch Hand
    Posts: 128
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    First of all: a very easy way is to use a GUI builder, that
    comes with every IDE.



    I read that: every IDE creates different code so if you want IDE independent code this is the best way.

    I use 10 objects, of which 8 are dummy invisible JLabels.
    This is to give the other panels some guiding as to where
    their components should come.



    Doesn't this kind of technique use a lot of resources ?

    What about my question about look-and-feel?
     
    Piet Souris
    Bartender
    Posts: 5465
    212
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    John Losty wrote:I read that: every IDE creates different code so if you want
    IDE independent code this is the best way.


    IDE independent code? Not sure what you mean by that.
    Actual code is always depending on something or someone.

    Doesn't this kind of technique use a lot of resources ?


    A couple of JLabels, it will certainly not fill up your memory.

    What about my question about look-and-feel?


    I do not not recall any question on the L&F.
    Do you have any particular L&F in mind?

    With

    you can inspect the available L&F's.

    Recently I used the 'nimbus' L&F, and I liked it.

    Edit: I just noticed your L&F question.
    If you decided on some L&F, say 'nimbus', this is how you could
    set it:
     
    John Losty
    Ranch Hand
    Posts: 128
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    The way I understand that is that When you create the same GUI with different IDEs, They each generate different code for the same GUI.

    If you decided on some L&F, say 'nimbus', this is how you could
    set it:



    My way of setting the L&F looks simpler but it doens't work, do you know the reason?
     
    Piet Souris
    Bartender
    Posts: 5465
    212
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Unfortunately, I have not been able to find any file 'swing.properties'.
    Never heard of, so I cannot help you with this.

    Anyway, to set the L&F in the program has the advantage that it
    will work on any machine, as long as it has that particular
    L&F.
    I have a library method like

    and it sets the L&F to the preferences specified, in that order. It defaults to the system L&F.
    That'll make it easy to test out quickly some L&Fs.
     
    John Losty
    Ranch Hand
    Posts: 128
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    But it looks to me that you have to include it in every program
     
    Piet Souris
    Bartender
    Posts: 5465
    212
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Yes. But if you want to have the same L&F on every
    other machine, then you should do that anyway.

    I just tried setting the default L&F in NetBeans to nimbus.
    (Tools -> Options -> Appearance -> L&F), but that merely
    sets the L&F of rhe IDE itself.

    So, what exactly did you try? As I said. nowhere do I see
    any swing properties file. What did you copy and from where?
     
    John Losty
    Ranch Hand
    Posts: 128
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    From: Oracle

    Specifying the Look and Feel: swing.properties File

    Yet another way to specify the current L&F is to use the swing.properties file to set the swing.defaultlaf property. This file, which you may need to create, is located in the lib directory of Sun's Java release (other vendors of Java may use a different location). For example, if you're using the Java interpreter in javaHomeDirectory\bin, then the swing.properties file (if it exists) is in javaHomeDirectory\lib. Here is an example of the contents of a swing.properties file:
    # Swing properties
    swing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel



    I will try this soon.
     
    Piet Souris
    Bartender
    Posts: 5465
    212
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Never knew this.

    But I gave it a try and indeed, it does work.

    For Windows: just open Notepad, put that sentence in

    and save it as swing.properties. In my case, it is the folder

    C:\Program Files\Java\jdk1.8.0_20\jre\lib

    You might need to open it as admin, or temporarily
    change the security settings.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic