Created
October 18, 2010 18:50
-
-
Save eed3si9n/632780 to your computer and use it in GitHub Desktop.
Flip that y axis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import javax.swing.*; | |
import java.awt.geom.*; | |
public class Foo extends JFrame { | |
private static final long serialVersionUID = 1L; | |
private JPanel jContentPane = null; | |
private JPanel jPanel = null; | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
SwingUtilities.invokeLater(new Runnable() { | |
public void run() { | |
Foo thisClass = new Foo(); | |
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
thisClass.setVisible(true); | |
} | |
}); | |
} | |
/** | |
* This is the default constructor | |
*/ | |
public Foo() { | |
super(); | |
initialize(); | |
} | |
/** | |
* This method initializes this | |
* | |
* @return void | |
*/ | |
private void initialize() { | |
this.setSize(300, 200); | |
this.setContentPane(getJContentPane()); | |
this.setTitle("JFrame"); | |
} | |
/** | |
* This method initializes jContentPane | |
* | |
* @return javax.swing.JPanel | |
*/ | |
private JPanel getJContentPane() { | |
if (jContentPane == null) { | |
jContentPane = new JPanel(); | |
jContentPane.setLayout(new BorderLayout()); | |
jContentPane.add(getJPanel(), BorderLayout.CENTER); | |
} | |
return jContentPane; | |
} | |
/** | |
* This method initializes jPanel | |
* | |
* @return javax.swing.JPanel | |
*/ | |
private JPanel getJPanel() { | |
if (jPanel == null) { | |
jPanel = new JPanel() { | |
protected void paintComponent(Graphics g) { | |
super.paintComponent(g); | |
Graphics2D g2 = (Graphics2D) g; | |
Insets insets = getInsets(); | |
// int w = getWidth() - insets.left - insets.right; | |
int h = getHeight() - insets.top - insets.bottom; | |
AffineTransform oldAT = g2.getTransform(); | |
try { | |
//Move the origin to bottom-left, flip y axis | |
g2.scale(1.0, -1.0); | |
g2.translate(0, -h - insets.top); | |
int xpoints[] = { 20, 30, 30, 35, 25, 15, 20 }; | |
int ypoints[] = { 10, 10, 30, 30, 45, 30, 30 }; | |
int npoints = 7; | |
g2.fillPolygon(xpoints, ypoints, npoints); | |
} | |
finally { | |
//restore | |
g2.setTransform(oldAT); | |
} | |
} | |
}; | |
jPanel.setLayout(new GridBagLayout()); | |
} | |
return jPanel; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do you not flip text?