I am new to swing core functionalities. I have experience in web designing. There is id
for uniqueness and class
for commonality.
<div class="x" id="div1"></div>
<div class="x" id="div2"></div>
If i want to set property for all the divs, i ll use class x.
.x
{
} or via javascript or jquery
If i want to access single div, i ll make use of id. Because it is unique.
In the same way is there anything in java swing buttons?Assume i have 2D array of jbuttons.
Tried so far
I found putClientProperty
and getClientproperty
. It sets and returns id.
btnName.putClientproperty('id',value);
My first question:
Is it correct way to set Unique id's? Is there any other ways?
JButton[][] btns = new JButton[5][5];
for(int i=0; i<5; i++)
{
for(int j=0;j<5;j++)
{
btns[i][j] = new JButton("Button"+i+j);
}
}
The above code will create 25 buttons with names.
My Second Question:
I am unaware of it.How to set classes so that i can enable or disable them with single line code? I meant
All the 25 buttons has a common class let it be tiles
JButton.find('tiles').setEnabled(false);
Is there anything similarly in java? I know the way to iterate and do it. But i want to reduce the number of lines, function calls. That's why i posted this question. Please let me know