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
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
posted 7 years ago
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..
posted 7 years ago
- 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: