Results 1 to 7 of 7

Thread: GUI Problem

  1. #1
    ellias2007 is offline Member
    Join Date
    Feb 2010
    Posts
    25
    Rep Power
    0

    Default GUI Problem

    Hi every body
    i made a JPanel with a custom background (photo) and it contains many labels (label1 ... label 4)
    each label (i) with a custom photo (photo i) as background ...
    a JComboBox is made for showing a label and hidding all other labels by selecting the desired label ...
    the problem is :
    when i select label1 for example : okey it shows the photo1
    when i select label2 for example : it shows the photo1 and photo2 still appears
    and when i select label3 also photos 1 2 3 are visibles one over others ... and also the Jpanel main photo is no longer visible...
    (each time i resize the application window a little, the photo1 photo2 disappear correctly but Jpanel main photo is still invisible...)

    Many thanks to any help

  2. #2
    ellias2007 is offline Member
    Join Date
    Feb 2010
    Posts
    25
    Rep Power
    0

    Default Re: GUI Problem

    ...also i used repaint() and revalidate() .. the problem exists ...

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: GUI Problem

    Quote Originally Posted by ellias2007 View Post
    (each time i resize the application window a little, the photo1 photo2 disappear correctly but Jpanel main photo is still invisible...)
    Never use getGraphics() of a Component.

    To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.

    And if you've cross posted this elsewhere, please tell us about it.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    ellias2007 is offline Member
    Join Date
    Feb 2010
    Posts
    25
    Rep Power
    0

    Default Re: GUI Problem

    Any help Please

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,669
    Rep Power
    5

    Default Re: GUI Problem

    No, don't pretend that Darryl never replied so you can keep doing as little as possible. Create an SSCCE and THEN you'll get "any help". First you make some effort to present a clear problem description.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    ellias2007 is offline Member
    Join Date
    Feb 2010
    Posts
    25
    Rep Power
    0

    Default Re: GUI Problem

    Hi all,
    thanks for your replies above....
    the complete code is too long and i can NOT paste it here completely ...
    here is a short but clear explanation :
    First i made many labels (3 for example) with a custom background and put them in a main JPanel :

    /// the main Panel
    mainPanel = new JPanel();
    mainPanel.setBounds(0,30,1420,830);
    mainPanel.setLayout(null);

    ///Label1 …
    Label1 = new JLabel();
    Label1.setBounds(170,125,1340,750);
    Label1.setLayout(null);
    ImageIcon StdBack = new ImageIcon("src/Graphics/Pnl1.png"); Label1.setIcon(StdBack);
    MainPanel.add(Label1);Label1.setVisible(false);

    /// and so for Label2 and Label3

    Then, a JComboBox calls the method ShowChoosed(int i) each time i select from it some JLabel :

    // Show the appropriate Label...
    public static void ShowChoosed(int i) {HidePanels();
    switch (i) {case 1 : Label1.setVisible(true); break;
    case 2 : Label2.setVisible(true); break;
    case 3 : Label3.setVisible(true); break;
    }
    }
    // Hide All Panels ...
    public static void HidePanels() {Label1.setVisible(false);
    Label2.setVisible(false);
    Label3.setVisible(false);
    }
    even if i use :
    mainPanel.repaint();
    mainPanel.revalidate();

    the problem still exists : When i choose Label 2 for example : the Label 2 is Visible okey, but the label 1 is also still visible and there is a clutter of labels...
    Please note that : if i resize the window a little (make it bigger or smaller a little) the label 1 disappears ....

    Thanks to any help

  7. #7
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,380
    Rep Power
    5

    Default Re: GUI Problem

    Please place your code between code tags [CODE][/CODE]. And where is the SSCCE? I can't answer your question as presented but I have done enough graphics programming to know that it doesn't take much code to put a couple of buttons in a JPanel.

    Also, where is your JFrame?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Replies: 0
    Last Post: 11-07-2012, 12:44 PM
  2. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 03:43 AM
  3. Replies: 9
    Last Post: 09-21-2010, 04:15 PM
  4. simple line problem / for loop problem
    By helpisontheway in forum New To Java
    Replies: 1
    Last Post: 11-17-2009, 06:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •