I'm trying to resize the icon so that it spans the entire button and is in the center of the button. When I try, it stretches my button and ruins everything else. How can I do it? My current code is:
In my class constructor ..
javax.swing.JButton Console = new javax.swing.JButton; ScaleButtonImage(Console, ConsoleEnabledImage);
Inside this class ..
private void ScaleButtonImage(javax.swing.JButton Button, java.awt.Image ButtonIcon) { double Width = ButtonIcon.getWidth(Button); double Height = ButtonIcon.getHeight(Button); double xScale = 28/Width;
VIEW:
.addGroup(layout.createSequentialGroup() .addComponent(Enable, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Graphics, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Debug, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Console, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
Then I will knit them all horizontally and vertically so that they are the same size.
Instead, it looks like this. Also, if I change the icon of the first button, all buttons are resized due to my limitations. How to make icons suitable for buttons?

source share