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.

Page 1 of 2 12 LastLast
Results 1 to 25 of 28

Thread: Autofocus a JPanel

  1. #1

    Default Autofocus a JPanel

    I need to autofocus a JPanel in my main frame. How do I accomplish this?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Autofocus a JPanel

    I suggest you check out the API for useful methods and give some of them a try to see what they do: JPanel (Java Platform SE 6)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Autofocus a JPanel

    Please define what you mean by autofocus. Do you mean for this JPanel to have focus for listeners? Call requestFocus on the component

  5. #5

    Default Re: Autofocus a JPanel

    Quote Originally Posted by copeg View Post
    Please define what you mean by autofocus. Do you mean for this JPanel to have focus for listeners? Call requestFocus on the component
    Focus so i can use KeyAdapter

  6. #6

    Default Re: Autofocus a JPanel

    Because at the moment I have to press the tab button to focus on my JPanel.

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Autofocus a JPanel

    What happened when you tried copeg's suggestion? Did you read the links I posted?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8

    Default Re: Autofocus a JPanel

    Quote Originally Posted by KevinWorkman View Post
    What happened when you tried copeg's suggestion? Did you read the links I posted?
    I read your links and copegs suggestion didnt work.

  9. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Autofocus a JPanel

    Quote Originally Posted by nivangerow View Post
    I read your links and copegs suggestion didnt work.
    Wow, you're a fast reader! Then I guess it's time to provide an SSCCE that demonstrates the problem and what you tried from those tutorials. Also, please read the link in my signature on asking questions the smart way, as you're making it really hard for people to help you today.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #10

    Default Re: Autofocus a JPanel

    Quote Originally Posted by KevinWorkman View Post
    Wow, you're a fast reader! Then I guess it's time to provide an SSCCE that demonstrates the problem and what you tried from those tutorials. Also, please read the link in my signature on asking questions the smart way, as you're making it really hard for people to help you today.
    Sorry, I will come back tomorrow, were eating dinner..

  11. #11

    Default Re: Autofocus a JPanel

    Right, lets try again. I am trying to make the key listener in my main JPanel to focus the keyboard as soon as the program is run.

  12. #12
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Autofocus a JPanel

    Quote Originally Posted by nivangerow View Post
    Right, lets try again. I am trying to make the key listener in my main JPanel to focus the keyboard as soon as the program is run.
    I gave you two links that should help you with that, and copeg very kindly gave you a suggestion. If you want help, we need more information than "that didn't work". What exactly did you try? Did you read the tutorials? Did you follow them? What about them didn't you understand? Where's your SSCCE? What does "didn't work" even mean? Did you see an exception, some strange behavior, a crash, a leprechaun, something else?

    Seriously, I urge you to read the link in my signature on asking questions the smart way. You aren't making it easy to help you, and we have hundreds of other posts we could be answering instead of guessing at what you're talking about.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  13. #13

    Default Re: Autofocus a JPanel

    Quote Originally Posted by KevinWorkman View Post
    I gave you two links that should help you with that, and copeg very kindly gave you a suggestion. If you want help, we need more information than "that didn't work". What exactly did you try? Did you read the tutorials? Did you follow them? What about them didn't you understand? Where's your SSCCE? What does "didn't work" even mean? Did you see an exception, some strange behavior, a crash, a leprechaun, something else?

    Seriously, I urge you to read the link in my signature on asking questions the smart way. You aren't making it easy to help you, and we have hundreds of other posts we could be answering instead of guessing at what you're talking about.
    What is a SSCCE? I followed the highlighted link but i still dont get it...

  14. #14
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Autofocus a JPanel

    Quote Originally Posted by nivangerow View Post
    What is a SSCCE? I followed the highlighted link but i still dont get it...
    It's a Short, Self-Contained, Compilable Example. That means it contains just enough code to demonstrate the problem- no extra stuff. But it's still compilable, so we can copy and paste it into our own editors and run it on our computers without doing stuff like adding a main method ourselves.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  15. #15

    Default Re: Autofocus a JPanel

    Quote Originally Posted by KevinWorkman View Post
    It's a Short, Self-Contained, Compilable Example. That means it contains just enough code to demonstrate the problem- no extra stuff. But it's still compilable, so we can copy and paste it into our own editors and run it on our computers without doing stuff like adding a main method ourselves.
    I looked at the links and tutorials. Its not what im looking for. I need the key listener to focus on the JPanel automatically, at the moment I have to press tab for it to focus. Can I give you a .jar file?

  16. #16
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Autofocus a JPanel

    Quote Originally Posted by nivangerow View Post
    I looked at the links and tutorials. Its not what im looking for. I need the key listener to focus on the JPanel automatically, at the moment I have to press tab for it to focus.
    And what did you try from the tutorials? What happened when you tried copeg's suggestion? Saying "it's not what I'm looking for" when in fact, it's EXACTLY what you're looking for if you would just READ is pretty frustrating and makes it even harder to help you.

    Quote Originally Posted by nivangerow View Post
    Can I give you a .jar file?
    Um, no. That wouldn't help me see the code you're running, which is pretty much the point. Plus, in the process of creating an SSCCE, oftentimes you'll figure the problem out yourself.

    There are too many other posts here with people who are more willing to follow suggestions, so I might be done trying to help you.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  17. #17

    Default Re: Autofocus a JPanel

    Quote Originally Posted by KevinWorkman View Post
    And what did you try from the tutorials? What happened when you tried copeg's suggestion? Saying "it's not what I'm looking for" when in fact, it's EXACTLY what you're looking for if you would just READ is pretty frustrating and makes it even harder to help you.


    Um, no. That wouldn't help me see the code you're running, which is pretty much the point. Plus, in the process of creating an SSCCE, oftentimes you'll figure the problem out yourself.

    There are too many other posts here with people who are more willing to follow suggestions, so I might be done trying to help you.
    I cant find it in the tutorial though. Instead of giving me links, you could just tell me what to do if you know what I need.

  18. #18
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Autofocus a JPanel

    Quote Originally Posted by nivangerow View Post
    I cant find it in the tutorial though. Instead of giving me links, you could just tell me what to do if you know what I need.
    Stop trying to "find" it and just read the tutorials. Do the examples, and play with them to see what the different methods do. And without an SSCCE, I can't even tell you what to do even if I wanted to!

    What you're doing right now is like this: Say I approached you and told you that my algorithm is slow and I want to improve it. You'd have to ask me what I meant by slow (seconds? minutes? hours? freezing up the program?), and more importantly, what the code for my algorithm looked like. In the meantime, maybe you would give me an article that talked about code optimization. How would you react if instead of following your suggestions or answering your questions or reading the article, I simply came back with a "no that didn't work"? What didn't work? What did you try? What did you learn from the tutorials?

    If you don't start being more forthright, I'm going to assume you're just being a troll on purpose.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  19. #19

    Default Re: Autofocus a JPanel

    Right. This is pretty much my problem: java - Obtaining focus on a JPanel - Stack Overflow
    and I will try some of the solutions that are in the comments on that page. If that doesnt work I will come back and bump this thread so you can see it.

  20. #20
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Autofocus a JPanel

    Quote Originally Posted by nivangerow View Post
    Right. This is pretty much my problem: java - Obtaining focus on a JPanel - Stack Overflow
    and I will try some of the solutions that are in the comments on that page. If that doesnt work I will come back and bump this thread so you can see it.
    Sigh. Gotta love copy-paste programmers...
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  21. #21

    Default Re: Autofocus a JPanel

    Quote Originally Posted by KevinWorkman View Post
    Stop trying to "find" it and just read the tutorials. Do the examples, and play with them to see what the different methods do. And without an SSCCE, I can't even tell you what to do even if I wanted to!

    What you're doing right now is like this: Say I approached you and told you that my algorithm is slow and I want to improve it. You'd have to ask me what I meant by slow (seconds? minutes? hours? freezing up the program?), and more importantly, what the code for my algorithm looked like. In the meantime, maybe you would give me an article that talked about code optimization. How would you react if instead of following your suggestions or answering your questions or reading the article, I simply came back with a "no that didn't work"? What didn't work? What did you try? What did you learn from the tutorials?

    If you don't start being more forthright, I'm going to assume you're just being a troll on purpose.
    No im not trolling. I just want to make my key listener Focus. And the key listener sits in my JPanel.

  22. #22

    Default Re: Autofocus a JPanel

    Quote Originally Posted by KevinWorkman View Post
    Sigh. Gotta love copy-paste programmers...
    Im not a copy-paste programmer, I spent half a year learning the basics of java, and now I have started to learn swing and I am making my own game.

  23. #23
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Autofocus a JPanel

    Quote Originally Posted by nivangerow View Post
    Im not a copy-paste programmer, I spent half a year learning the basics of java, and now I have started to learn swing and I am making my own game.
    You're copying and pasting partial solutions you find on the internet without trying to understand them so you can avoid reading through a simple tutorial. That's a copy-paste programmer. You were unwilling to create an SSCCE so people could advise you on your code. That's a copy-paste programmer.

    And you ignored the suggestions you were given, and then argued about it for the rest of the time. That's a troll.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  24. #24

    Default Re: Autofocus a JPanel

    Quote Originally Posted by KevinWorkman View Post
    You're copying and pasting partial solutions you find on the internet without trying to understand them so you can avoid reading through a simple tutorial. That's a copy-paste programmer. You were unwilling to create an SSCCE so people could advise you on your code. That's a copy-paste programmer.

    And you ignored the suggestions you were given, and then argued about it for the rest of the time. That's a troll.
    I dont have the time to make a SSCCE and im only copying the solutions because I am relatively new to swing. And I learn from using those solutions on a daily basis. Thats how I learn, everyone learns differently.
    Close this thread, even google is more helpful than you are. And I didn't mean to offend you. Just close this thread.

  25. #25
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Autofocus a JPanel

    Quote Originally Posted by nivangerow View Post
    I dont have the time to make a SSCCE and im only copying the solutions because I am relatively new to swing. And I learn from using those solutions on a daily basis. Thats how I learn, everyone learns differently.
    Close this thread, even google is more helpful than you are. And I didn't mean to offend you. Just close this thread.
    I'm not offended, I'm just pointing out that your approach makes it difficult to help you. It's not a ridiculous request to ask you to provide some example code that demonstrates what you're talking about. And it's not ridiculous to point you to a tutorial that contains the answer you're looking for. Learning how to program takes a lot of time and patience, so if you don't have the time to even narrow your problem down to some code for a stranger to look at for free, then I wish you the best of luck. You might very well find a copy-paste solution to use to solve this basic problem, but I think your approach is going to come back to bite you in the future when you realize all these shortcuts kept you from actually learning anything.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Page 1 of 2 12 LastLast

Similar Threads

  1. Broken JPanel?
    By psu in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 22nd, 2011, 11:11 AM
  2. JButton on JPanel
    By JavaLearner in forum AWT / Java Swing
    Replies: 4
    Last Post: March 26th, 2010, 07:46 AM
  3. how to destroy JPanel?
    By amahara in forum AWT / Java Swing
    Replies: 2
    Last Post: February 28th, 2010, 03:41 AM
  4. How to copy image from one jpanel to another jpanel
    By ramanavarayuri1986 in forum AWT / Java Swing
    Replies: 0
    Last Post: February 15th, 2010, 02:36 AM
  5. Creating and displaying a JPanel inside another JPanel
    By JayDuck in forum AWT / Java Swing
    Replies: 1
    Last Post: April 7th, 2009, 08:02 AM

Tags for this Thread