So, I have some JButton
s and I need to change the font size according to how big the screen is. The size of the JButton
s changes automatically since I'm using a GridLayout
layout. I've tried some of the following code, running in a thread:
@Override
public void run() {
int i = 0;
int l = 0;
while(true) {
for(int x=0; x<buttons.length; x++) {
while(true) {
int size = 300;
size--;
Font font = buttons[x].getFont().deriveFont((float) size);
if(font.canDisplayUpTo(buttons[x].getText()) == 1) {
buttons[x].setFont(font);
o(font.getSize());
break;
}
}
buttons[x].setText(String.valueOf( l ));
}
l++;
try {
Thread.sleep(100);
} catch (InterruptedException ex) {}
}
}