import javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class ScalePanel extends JPanel
{
public ScalePanel()
{
setPreferredSize( new Dimension( 300, 200 ) );
setBackground( Color.white );
setLayout( null );
JTextField text = new JTextField( "haha" );
text.setEnabled( false );
text.setBounds( 50, 50, 100, 30 );
add( text );
setEnabled( false );
} private static void scaleComponent(Component comp, double scale)
{
int w = comp.getWidth();
int h = comp.getHeight();
comp.setSize((int) (w * scale), (int) (h * scale));
if(comp instanceof Container)
{
Container container = (Container) comp;
Component[] comps = container.getComponents();
for(int i=0; i<comps.length; i++)
scaleComponent(comps[i], scale);
}
} public static void main( String[] args )
{
final JFrame f = new JFrame();
f.setSize( 500, 400 );
final ScalePanel panel = new ScalePanel();
final JScrollPane jsp = new JScrollPane( ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED );
jsp.getViewport().setView( panel );
Container pane = f.getContentPane();
pane.add( jsp ); JButton b = new JButton( "scale" );
b.addActionListener( new AbstractAction() {
public void actionPerformed( ActionEvent e )
{
double scale = 2;
scaleComponent(panel, scale);
}
});
pane.add( b, BorderLayout.SOUTH ); f.show();
}