Pass Focus between Buttons

0

Even if it seems very simple, ps is creating problems for me ... I have a window where I have implemented a ScrollPane and inside a panel. more buttons and a table (so far so good). What I want is that when I click on a button this happens with the enter to the other button and so on but as I go through the buttons the ScrollPane will move without the need for me with the mouse have to move it to see the rest of buttons, if not that as I focus on the buttons and they go from one to another the ScrollPane also move and visualize everything.

I leave an image (and a little explanation to be more exact)

    
asked by Bloom 08.08.2018 в 17:22
source

1 answer

0

For those who have problems similar to mine and do not know how to solve it here I leave the answer. :)

In my case, I wanted it to move the buttons and other text boxes, etc. It is moving also with it my JScrollPane then I thought that with the focus, this would also pass by default. But it was not like that, then researching arrive at the following. Needs if the focus to move from one booth to another but what I needed to add was the movement of my JScrollPane , so that together they move the two.

1. Give the action to my box (you get it by double clicking on a button):

private void mibotonActionPerformed(java.awt.event.ActionEvent evt) {                                         
  miboton.requestFocus(true);
} 

2. Give movement to my ScrollPane (there are two ways):

//Que baje de uno el ScrollPane (hasta el final)
miscroll.getVerticalScrollBar().setValue(miscroll.getVerticalScrollBar().getMaximum());

//Que baje de a poquitos (calcular la distancia entre cajas)
miscroll.getVerticalScrollBar().setValue(10);//el 10 se refiere a la cantidad de espacio que quiere que baje
    
answered by 08.08.2018 в 20:48