• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Switch between the JButton using Keyboard

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hii all... Need your help..
I want to add JButtons in JPanel using FlowLayout or any other layout and moving between the JButtons using Up and Down key..
Having problem in moving up and down because i dont know the rows and columns of JButton.
My code so far...



I am not able to write the code for Up & Down key because FlowLayout arranges the component using location.. So i m not getting the rows and column of a selected button.. and i cant use other layout because if the screen size changes the JButton get overlaped in all other layout
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. don't use KeyListener for JButton, Buttons JComponents, all these events are implemented in API and correctly, every mouse & key events are accesible from ButtonModel too (by listening from ChangeListener)

2. FlowLayout is default LayoutManager implemented in JPanels API, there no reason to define with uncompilable new FlowLayout == new FlowLayout()

3. use GridLayout, then you can to easilly determine Row or Column, the same with GridBagLayout, SpringLayout, define those coordinates by using put/getClientProperty to each of JButtons

4. for navigation (setFocus, moving with Focus) to use KeyBindings added to JPanel

5. override getPreferredSize for JPanel

6. then isn't (put a.m. points 3-5 together) required to hold JButtons into any of arrays

7. for better help sooner post an SSCCE, short, runnable, compilable, just about JFrame with JPanel contains JButtons

 
Nainisha Bihani
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply and the help Mr. M Korbel.. But still i have some questions..
1. I had used Grid Layout.. But the problem is that when the JPanel is being compressed horizontally(using Mouse) the Jbuttons get overlapped to each other.
2.In gridlayout i have to specify either row or column.. But suppose I had specified 7 columns in a row.. If my monitor size get changed then it will reflect the JButtons position..

I want to make it like Windows 7.. In windows suppose there is 5 folders in a row in a window and when we compressed it with mouse it automatically arranges the folder..
This can easily be done using flowlayout... It automatically arranges the component..
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- to avoiding any guessing I wrote, see my point 7th. for better help sooner post an SSCCE, short, runnable, compilable, just about JFrame with JPanel contains JButtons

- correct me if I wrong I saw similair question on another Java forum

- can start with (probably you can to ignore, to disable code execution for code line gb.addActionListener((ActionListener) EventHandler.create(ActionListener.class, this, "actionName" + row + "A" + col));)

 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic