Pessoal,
To com um problema,
Quando utilizo o scale do Graphics2D em um componente, (para testes um exemplo o JButton) a area de foco do click não recebe o scale…
O que falta pra isso funcionar?
Para exemplo segue o código completo:
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author lcl
*/
public class TesteComponentZoom extends JPanel
{
double ratio = 3;
JButton b;
public static void main( String args[] ) throws Exception
{
TesteComponentZoom t = new TesteComponentZoom();
JFrame f = new JFrame();
f.add( t );
f.setSize( 800, 600 );
f.setVisible( true );
}
public TesteComponentZoom() throws Exception
{
initComponents();
b = new JButton( "Teste" )
{
public void paintComponent( Graphics g )
{
Graphics2D g2d = (Graphics2D)g;
g2d.setClip( null );
g2d.scale( ratio, ratio);
super.paintComponent( g2d );
}
};
add( b );
}
public void initComponents()
{
setBackground( Color.lightGray );
InputMap imap = getInputMap( JComponent.WHEN_IN_FOCUSED_WINDOW );
imap.put( KeyStroke.getKeyStroke( KeyEvent.VK_ADD, InputEvent.CTRL_MASK ), "PresenterPane.keyPress" );
imap.put( KeyStroke.getKeyStroke( KeyEvent.VK_SUBTRACT, InputEvent.CTRL_MASK ), "PresenterPane.keyPress" );
ActionMap amap = getActionMap();
Action pressedAction = new AbstractAction()
{
public void actionPerformed( ActionEvent e )
{
ratio += ((e.getActionCommand().equals( "+" ) ? 0.5 : -0.5));
System.out.println( "Pressed " + ratio );
repaint();
}
};
amap.put( "PresenterPane.keyPress", pressedAction );
}
}