Results 1 to 1 of 1
Thread: JScrollPane and AffineTransform
- 12-17-2009, 02:47 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 1
- Rep Power
- 0
JScrollPane and AffineTransform
Ok, I want to ask something. I want to be able to create a JFrame, to put inside the JFrame a JScrollPane, which ViewPort contains another JPanel. The JPanel does nothing else than to paint a rectangle. But I add a JToolBar in the JFrame with one Button for Rotating. When I click the button the rectangle in the JPanel gets rotated. So far so good. But when I move the Scrolls of the JScrollPane the Rectangle moves as well and I want it to stay on the position on the JPanel where I've put it on the beginning.
Here is my code for a better understandment.
Java Code:public class MainFrame extends JFrame implements ActionListener { private AffineTransform af; public MainFrame(){ super(); MainPanel mp = new MainPanel(this); JButton rotate = new JButton("Rotate"); rotate.setActionCommand("rotate"); rotate.addActionListener(this); JToolBar jtb = new JToolBar(); jtb.add(rotate); JScrollPane jsp = new JScrollPane(); jsp.getViewport().add(mp,BorderLayout.CENTER); this.add(jsp); this.add(jtb,BorderLayout.PAGE_START); af = new AffineTransform(); } public static void main(String args[]){ MainFrame mf = new MainFrame(); mf.setSize(400, 400); mf.setVisible(true); } public void setRotate(double angle, int x, int y){ af.rotate(angle, x, y); } public AffineTransform getAf(){ return this.af; } @Override public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("rotate")){ this.setRotate(30, 100, 100); } } public void setAf(AffineTransform af) { this.af = af; } } public class MainPanel extends JPanel { private MainFrame mf; public MainPanel(MainFrame mf){ this.mf = mf; this.setPreferredSize(new Dimension(300,300)); } public void paint(Graphics g){ Graphics2D g2 = (Graphics2D)g; g2.setTransform(mf.getAf()); g.drawRect(50, 50, 100, 100); this.mf.repaint(); } }
Similar Threads
-
JTextPane Font's with AffineTransform Rendering
By StormyWaters in forum AWT / SwingReplies: 7Last Post: 09-18-2009, 09:56 PM -
[SOLVED] AffineTransform
By robocop in forum New To JavaReplies: 2Last Post: 03-25-2009, 05:54 PM -
AffineTransform help
By tones in forum New To JavaReplies: 4Last Post: 12-19-2008, 07:24 AM -
AffineTransform demo
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 10:59 PM -
affineTransform rotation
By MichYer in forum AWT / SwingReplies: 0Last Post: 07-18-2007, 08:55 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks