Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Components locations being reset after revalidation

  1. #1
    Member Hikaros's Avatar
    Join Date
    Sep 2013
    Posts
    42
    My Mood
    Love
    Thanks
    10
    Thanked 2 Times in 2 Posts

    Default Components locations being reset after revalidation

    So i'm into a personal project (haha it is definitely way more of what i know i can do -skill/knowledge wise-, but this is kind of the point), if you ever played Magic: The gathering (through magic workstation) or recently Hearthstone you can get the idea of what i want to do (not as fancy as Hearthstone though, just... better looking than mws).

    I have no plans for AI or such, i want it to be open, as in the user does what he wants, no forced rules by the system or anything, everything is completely manual (just like in magic workstation).

    Starting off with the GUI since i have honestly no idea about how to manage a really dynamical gui (moving components), then with the network stuff since i have a better understand about that(or at least i think).

    starting with the most dynamical part of the GUI: moving cards and larger card preview.

    so i've made my class for cards which is a JPanel and paint the cards on it, i can move it around playing with the setLocation but i have a serious problem, everytime i add another card (another Jpanel) i have to revalidate the jframe and that resets the locations. I know this is because of the Layout but i can't just remove it or else it won't add more components later on (obviously haha), so i have no idea how to approach this.

    Can someone tell me what to do about that?


    TL;DR version: I'm playing with the setLocation property of some components and everytime i add another component (in run time) i have to revalidate and it resets the locations, how can i stop that from happening?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,817
    My Mood
    Mellow
    Thanks
    177
    Thanked 627 Times in 614 Posts

    Default Re: Components locations being reset after revalidation

    For those of us not familiar with the interface, can you describe it? How many JPanels will be shown at any one time? When JPanels are added, what should that look like (do they stack next to each other, underneath, on top, etc.?)

    As you've learned, adding/removing components to an interface at run time can be challenging, but there are or should be ways to achieve the effect you want if we understand what that is.

  3. #3
    Member Hikaros's Avatar
    Join Date
    Sep 2013
    Posts
    42
    My Mood
    Love
    Thanks
    10
    Thanked 2 Times in 2 Posts

    Default Re: Components locations being reset after revalidation

    haha it is very very hard ):

    there can be even hundreds of JPanels (cards) showing at the same time, you should be able to change the position (horizontal/vertical), you can stack them (put them on top of any one you want and as much as you want, as long as you are in your card area), this is how it can look:



    and you can have more and more cards, it should be limitless.

    now, you see the card preview at the right side? i want that to show on top of your cards in your hand (the lower side) kind of like a tooltip.

    this is how hearthstone looks and this is how it behaves when you hover the mouse over a card

  4. #4
    Member Hikaros's Avatar
    Join Date
    Sep 2013
    Posts
    42
    My Mood
    Love
    Thanks
    10
    Thanked 2 Times in 2 Posts

    Default Re: Components locations being reset after revalidation

    Solved it, thought id just post the update in case someone elses needs something like this.

    The problem is that i didn't know we could use absolute positioning,thought that we HAD to use a layout manager but that is not the case, the coding without the layout manager is quite complicated but this is what i was looking for: Doing Without a Layout Manager (Absolute Positioning) (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)

Similar Threads

  1. Replies: 6
    Last Post: May 10th, 2013, 12:47 PM
  2. File locations?
    By Willsy in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: April 10th, 2013, 10:30 AM
  3. Need help with pie charts locations
    By Wise girl in forum Object Oriented Programming
    Replies: 10
    Last Post: June 13th, 2012, 03:28 PM