Vertical Labels

I'm having a problem with getting text to read downwards using 'JLabels' (but I don't mind using normal 'Label's).
If anybody knows how to either :-
1) Get a Label or JLabel to write downwards or,
2) Rotate a Component or JComponent 90 degrees
I would be very thankful. I've looked as much as I can into the Online Javadoc Overview without finding a solution.
Thanks

The obvious way to do 2) is to override the size accessor methods (getPreferredSize etc) to invert the width and height and then implement paint / paintComponent as: protected void paintComponent(Graphics g)
    if (g instanceof Graphics2D)
        // Let affine transforms handle it.
        Graphics2D g2d = (Graphics2D)g;
        g2d.rotate(-Math.PI / 2);
        // It may also be necessary to translate it. Left as an exercise to the reader.
        super.paintComponent(g2d);
        // Now undo our affine transforms, starting with the translation if used.
        g2d.rotate(Math.PI / 2);
        // g is now in the original affine space.
    else
        // Have to paint onto a BufferedImage or somesuch, rotate that and paint.
        // Note: this will be very slow. Optimise by reusing BufferedImage when size doesn't change.
        Dimension actualSize = getSize();
        BufferedImage img = new BufferedImage(actualSize.height, actualSize.width, BufferedImage.TYPE_INT_ARGB);
        super.paintComponent(img.getGraphics());
        // Construct a suitable affine transform - again, translation may be necessary.
        AffineTransform trans = new AffineTransform();
        trans.rotate(-Math.PI / 2);
        // Transform the image.
        AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_NEAREST_NEIGHBOUR);
        BufferedImage imgRot = new BufferedImage(actualSize.width, actualSize.height, BufferedImage.TYPE_INT_ARGB);
        op.filter(img, imgRot);
        // Should really use an ImageObserver?
        g.drawImage(imgRot, 0, 0, null);
}Note: this is not production-quality code. It is entirely untested. Use at own risk.

Similar Messages

  • Checkbox with vertical label - FB mobil app

    How can I create in Flash Builder a checkbox with a vertical label. Has someone an example code?
    The label should be under the checkbox (but in center):
    CheckBox
    L
    A
    B
    E
    L
    Great thanks, M.

    I think the whole reason that this post was even necesary was because the original Check box wasn't written properly (see my comments on this page http://livedocs.adobe.com/flex/3/html/help.html?content=cellrenderer_4.html ).  Note that mx checkbox implements IDataRenderer, so you should be able to use it as a renderer with this tweak, as long as the Spark DataGrid allows you to set column alignment as MX data grid (or you don't need it centered).
    In Flex 4, ItemRenderer is really just a Group with a couple of extra bells and whistles.  At the simplest level, you can just bind its selected property to some boolean field on the data object if you know its format in advance.  However, that's not going to give you a reusable check box.  To do that, you need to either write code that can translate the string label field into a Boolean, or something that can combine the DefaultDataGridRenderer's data property with the dataField property on DefaultDataGridRenderer's column object and again come up with a Boolean.
    You can either make this Boolean a Bindable variable or, if you're comfortable with the component life cycle, you can do the getter/setter + commitProperties to set it more directly on a custom Check Box skinPart.
    HTH;
    Amy

  • Vertical labels displaying horizontaly Crystal enterprise XI

    Hi,
    I have a report where Page Header A has a few horizontal fields and labels, and  Page Header B has a dozen or so vertical field labels only.
    The report looks good when viewed from Crystal design, although when the report is mounted on the staging server the vertical labels (page headerB) display as horizontal. ?!?!?!?!
    I'm using crystal design XI ver.11.0.0.2495
    The staging server is using busniness objects enterprise ver. 11
    can anyone help me to figure out why the vertical labels are displaying horizontal on the enterprise version ????
    thanks !
    Rick

    Rick,
    Measure the height of each section, and use the measurement in a stored variable, to accumulate the current length of the report. Then use the section expert for each section, to check the current value of said variable.
    It will not work in all cases, but maybe with some changes for your scenario it will help.
    Regards,
    Kyle McAdam,
    Senior Engineer, Customer Assurance
    Business Objects an SAP Company
    Edited by: Kyle McAdam on Jul 7, 2008 7:17 PM

  • Vertical labels for ChartApplet class

    Hello everybody.I am developing a web applcation(javascript-applets) and I am using the ChartApplet() class for displaying charts in the web. Unfortunately, I cannot find any parameter for displaying the labels vertically on x axis. I found that the BarChartApplet() class has one;the barLabelAngle.
    Does anyone know if there any similar parameter for ChartApplet() class?
    Does anyone know if there is any site to download free the BarChartApplet()?
    Thank you for your time.

    I think you have got confused between Java3D and ChartApplet. As far as I can tell there is no relationship between them.

  • How to set the text of a cell in Numbers to vertical direction? Tks.

    Hi
    In Numbers, please tell me how to switch the text of a cell to vertical direction?
    Tks.

    Hi Kyle,
    In Numbers, nothing having to do with a table can be rotated. (In Pages an entire Table can be rotated, but not text within a Table.)
    There have been many suggestions posted here over the life of iWork for vertical labels. Most fall into three categories:
    1. Type one letter, Option-Return, type another letter, Option-Return, and so forth.
    2. Type label in a Text Box, rotate the box, position the box over the table, covering the cell where you need a label.
    3. Create a PDF graphic with rotated text and insert it into table cell as Background Fill.
    The third option is clearly the best. The steps for option three are:
    Insert Text Box
    Type label into the box
    Rotate the text box
    Select the text box (not the text inside the box)
    Command-C
    Switch to Preview.app
    Command-N
    Command-C
    Switch to Numbers
    Click on Cell where the label goes
    Command-V
    It sounds worse than it is. You can reuse the Text Box so you don't end up with a sheet full of them.
    Regards,
    Jerry

  • Feature Request: Control Text Orientation on Chart Labels

    I notice that chart labels will automatically rotate 90 degrees counterclockwise when there is not enough space to display them vertically.  However, I would like to be able to control this behavior so that I can make vertical labels when my charts are larger.  A simple toggle option would be great.

    In the Alerts tab of iChat preferences, select Video Invitation from the Event pop-up menu. Then select the Run Applescript checkbox and select Auto Accept.applescript from the adjacent pop-up menu.
    Granted, this doesn't give you password authentication, but I don't believe anything is available for providing that capability.
    Hope this helps.
    Palms831

  • Reverse Chart Label Column

    Hello,
    I have a numbers spreadsheet that contains search engine rankings. The lower the number the better the result (#1 is highest of course) and I am trying to figure out how to display the data in a line graph where the left hand vertical labels go from lowest to to highest. They way it is by default, as rankings improve the line goes down making it appear as if performance is dropping.
    Thanks!

    I would reverse the ranking scheme so that #1 becomes the largest numbered item. Once plotted, you can overlay the X-Axis labels with a scale that has "1" at the top and however large a number you want at the bottom.
    Jerry

  • What are pin names and numbers rotated?

    I copied an existing schematic symbol into my user data base, changed the part number and saved it. Then I placed the component into the schematic and the pin names and numbers were totally screwed up. All vertical names and numbers were rotated horizontal.
    See the attached picture. On the left is the image shown in the "Select a Component" dialog. On the right is what I get when I place the component.
    WYSINWYG!
    How do I correct this, and is this going to happen every time I place a component with vertical labels?
    Phil
    Solved!
    Go to Solution.
    Attachments:
    screwed up symbol.jpg ‏235 KB

    The original component a FT 232DM, but this is no longer manufactured. The FT232BL is a pin for pin replacement. All I wanted to do was change the component name.
    I copied the FT232DM from the schematic sheet into my User Database. Then I opened the component in the Symbol Editor, changed the name to FT232BL, and saved it into my User Database. What you see in the image posted earlier are the symbol as it appears in the Symbol Editor (left) and as it appears after I placed the FT232BL into the schematic.
    I have solved the problem - I can't wait days and days for a Tech Support answer on a job with a short deadline.
    I edited the component in Symbol Editor and changed pin rotation from Auto to horizontal or vertical as appropriate. Then when the part was placed in the schematic the vertical pin names and numbers appeared as they should.
    It is very peculiar that the program displays the symbol one way in the Symbol Editor and then places it in the schematic with a different configuration. The way the user designs the part in the Symbol Editor is the way the part should be placed in the schematic.
    Phil

  • AffineTransform problem caused by JMenuBar + JTabbedPane

    Hello everyone.
    I am starting to think that there is a bug in Java, because otherwise what else could cause the problem I am experiencing? Namely: adding a panel with a vertical text (like a Y axis caption) using an AffineTransform (see SSCCE below) causes this text to be misplaced in some cases.
    Variant A
    Panel is added directly to the application frame. This causes no problems and everything is as it should be.
    Variant B
    Panel is placed on a tabbed pane and a menu bar is associated with the frame. The vertical text is now shifted away from the place where it should be by the height of the menu bar plus the height of tabs on the tabbed pane. Why is this happening? Am I doing something wrong?
    Moreover, when one switches to another tab and then back, the text is now shifted only by the height of the tabs. Once the application window is resized at least a bit, the text jumps right back to the position shifted by tab height plus menu bar height... Strange, strange, strange...
    SSCCE
    import java.awt.*;
    import java.awt.font.FontRenderContext;
    import java.awt.geom.*;
    import javax.swing.*;
    class MyPanel extends JPanel {
        MyPanel() {
            this.setPreferredSize(new Dimension(300, 200));
        @Override
        protected void paintComponent(Graphics g) {
            Graphics2D g2D = (Graphics2D)g;
            int g2DWidth = this.getWidth();
            int g2DHeight = this.getHeight();
            // Horizontal line in the middle of the panel (indicates the position
            // where the middle of the vertical label should be)
            g2D.drawLine(30, (int)(g2DHeight / 2), g2DWidth - 10,
                    (int)(g2DHeight / 2));
            // Vertical label
            AffineTransform origTransform = g2D.getTransform();
            AffineTransform rotate = AffineTransform.getRotateInstance(
                    -Math.PI / 2.0, 0, 0);
            g2D.setTransform(rotate);
            String text = "Centered?";
            FontRenderContext frc = g2D.getFontRenderContext();
            Font font = UIManager.getFont("Label.font");
            Rectangle2D bounds = font.getStringBounds(text, frc);
            g2D.drawString(text, -(int)((g2DHeight + bounds.getWidth()) / 2), 20);
            g2D.setTransform(origTransform);
    class Main {
        private static void createAndShowGUI() {
            // Menu bar
            JMenuBar menuBar = new JMenuBar();
            JMenu menu = new JMenu("Menu");
            JMenuItem menuItem = new JMenuItem("Menu Item");
            menu.add(menuItem);
            menuBar.add(menu);
            // Tabbed pane
            JTabbedPane tabbedPane = new JTabbedPane();
            JPanel panel = new MyPanel();
            tabbedPane.add(panel);
            JLabel label = new JLabel("Nothing interesting's going on here...");
            tabbedPane.add(label);
            // Frame
            JFrame frame = new JFrame();
            // TRICKY PART HERE =========================================
            // [(Un)comment lines as necessary]
            // Variant A: the panel only --------------------------------
            //frame.add(panel);
            // Variant B: menu bar + panel on a tabbed pane -------------
            frame.setJMenuBar(menuBar);
            frame.add(tabbedPane);
            // ==========================================================
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }Thanks for any help.
    Best regards,
    vt
    Edited by: -vt- on 23-Apr-2010 13:08

    You are ignoring the current transform on the Graphics, use the following instead of setTransform():
    g2D.rotate(-Math.PI / 2.0, 0, 0);

  • Client side ERROR MESSAGE THROWN TWICE

    Hi,
    In our application we are having a af:inputText component, which has a client side validation. When the validation fails the intended error message is thrown twice on the screen. Below is the component code snippet,
    <af:inputText label="#{inventoryUIBundle.RANGE_TO}" autoSubmit="true"
    rendered="#{pageFlowScope.TelephoneNumberEditBean.addMode}" columns="20"
    maximumLength="#{pageFlowScope.TelephoneNumberEditBean.maxLength}"
    value="#{pageFlowScope.TelephoneNumberEditBean.maskedRangeTo}"
    binding="#{backingBeanScope.rangeToComponent}"
    id="number-rangeto">
    <af:validateRegExp pattern="[\\d\\s\\*\\#\\+\\-\\.\\,\\(\\)\\\\\/]+" messageDetailNoMatch="Only number, space and special character - + ( ) . , / \ * # are allowed."/>
    </af:inputText>
    Can any one provide any clue as to why this is happening.
    regards,
    Chandra.

    Another location where I have this issue,
    <af:inputText value="#{pageFlowScope.PlaceEditBean.entityObject.vertical}"
    label="#{inventoryUIBundle.VERTICAL}"
    maximumLength="25" autoSubmit="true"
    id="place1-vertical" partialTriggers="place1-latitude place1-longitude"
    binding="#{backingBeanScope.verBinding}"
    valueChangeListener="#{pageFlowScope.PlaceEditBean.onChangeVnH}">
    <af:validateRegExp pattern="(-)?(\\d){1,10}\\.(\\d){1,10}" messageDetailNoMatch="Only decimal numbers are allowed for vertical."/>
    </af:inputText>
    In the above tag set, there is a ValueChangeListener. This also has a double message issue.
    regards,
    Chandra.

  • IE vs Firefox layout problem

    I'm using the cfform type="xml" to create the following form
    http://www.cisaustin.org/volunteer-amagrum/vol-app-long-student-version-page5.cfm
    First I can't get the label to be next to the cftextarea, and
    secondly it looks way different in IE and Firefox browser.
    Any suggestions how to fix this?
    Thanks

    quote:
    Originally posted by:
    drforbin1970
    Post some code.
    Here is the code from that page
    <cfform name="contactForm" format="xml" skin="lightgray"
    width="600" method="post" action="scripts/ProcessApp.cfm">
    <cfinput type="hidden" name="volunteertype"
    value="retvol">
    <cfformgroup type="vertical" label="Community Volunteer
    Application Form Page 5">
    <!---============================= sign off
    ===============================================================================--->
    <cfformgroup type="horizontal">
    <cfformitem type="html">Have you ever been convicted
    of
    anything other than a minor traffic
    violation?</cfformitem>
    <cfinput type="Radio" name="violation" value="No"
    label="No">
    <cfinput type="Radio" name="violation" value="Yes"
    label="Yes">
    </cfformgroup>
    <cftextarea label="If yes, list all such offenses and
    state, date, name of court and disposition" name="offense"
    cols="70" rows="" wrap="virtual"></cftextarea>
    <cfformitem type="html"><strong>Consent For
    Criminal Background Check</strong><br>
    <font size="-2">I hereby give permission for
    ................................. bla bal bal ...and other expenses
    resulting from
    the investigation of my background in connection with my
    application to become a CIS volunteer.</font>
    </cfformitem>
    <cfformgroup type="horizontal">
    <cfinput type="Text" name="signoff" message="Please enter
    name to certify the application" required="Yes" size="30"
    maxlength="30" label="Full Name">
    <cfoutput>
    <cfinput type="Text" name="appdate"
    value="#DateFormat(now(), 'mm/dd/yyyy')#" message="Date of
    Application" validate="date" required="Yes" size="10"
    maxlength="10" label="Date">
    </cfoutput>
    </cfformgroup>
    <!----------------------------------------------------------------------------------->
    </cfformgroup>
    <cfinput type="submit" name="BtnSubmit" value="Submit
    Form">
    </cfform>

  • Access 2007/2010 Which Report Wizard

    Does anyone know the report wizard template which auto-rotates the field label to vertical as it is created?
    I have created one report with a layout I am happy with using a wizard, but didn't note which one I used :(
    Don't have the patience/knowledge to create one from scratch and there are about 20 fields to display.
    The result gives separate vertical labels for each field but leaves the field data horizontal which works well on a landscape report.
    This could have been created in either 2007 or 2010 home or work versions of Access.
    Thanks
    Phil

    Hi Phil,
    Thanks for sharing your experience here and welcome to post here again.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • NEED HELP IN LABELLING A TRIANGLE _ VERTICES

    PLEASE HELP ______
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.text.NumberFormat;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.DefaultTableCellRenderer;
    import java.lang.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import java.awt.FileDialog;
    import java.io.*;
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import javax.swing.JFrame;
    public class Geometry {
        CardLayout cards;
        JPanel panel;
        public Geometry() {
            cards = new CardLayout();
            panel = new JPanel(cards);
            addCards();
            JFrame f = new JFrame("Geometry");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setJMenuBar(getMenuBar());
            f.getContentPane().add(panel);
            f.setSize(500,500);
            f.setLocation(0,0);
            f.setVisible(true);
            f.addMouseMotionListener(
            new MouseMotionListener() { //anonymous inner class
                //handle mouse drag event
                public void mouseMoved(MouseEvent e) {
                   System.out.println("Mouse  " + e.getX() +","  + e.getY());
                public void mouseDragged(MouseEvent e) {
                    System.out.println("Draggg: x=" + e.getX() + "; y=" + e.getY());
            //            public void mouseMoved(MouseEvent me) {
            //                System.out.println("Moving: x=" + me.getX() + "; y=" + me.getY());
            //        panel.addMouseMotionListener(
            //        new MouseMotionListener() { //anonymous inner class
            //            //handle mouse drag event
            //           public void mouseDragged(MouseEvent me) {
            //               setTitle("Dragging: x=" + me.getX() + "; y=" + me.getY());
            //            public void mouseMoved(MouseEvent me) {
            //                setTitle("Moving: x=" + me.getX() + "; y=" + me.getY());
        private void addCards() {
            // card one
            TriangleModel tri = new TriangleModel(175,100,175,250,325,250);
            TriangleView view  = new TriangleView(tri);
            JPanel panelOne = new JPanel(new BorderLayout());
            panelOne.add(view.getUIPanel(), "North");
            panelOne.add(view);
            panelOne.add(view.getTablePanel(), "South");
            panelOne.setName("Pythagoras's Theorem");
            panel.add("Pythagoras's Theorem", panelOne);
                  view.addMouseMotionListener(
            new MouseMotionListener() { //anonymous inner class
                //handle mouse drag event
                 public void mouseMoved(MouseEvent e) {
                    System.out.println("Mouse at " + e.getX() +","  + e.getY());
               public void mouseDragged(MouseEvent e) {
                   System.out.println("Dragging: x=" + e.getX() + "; y=" + e.getY());
            // card two
            TestModel trin = new TestModel(175,100,175,250,325,250);
            TestView viewn  = new TestView(trin);
            JPanel panelTwo = new JPanel(new BorderLayout());
            panelTwo.add(viewn.getUIPanel(), "North");
          // panelTwo.setBackground(Color.blue);
            panelTwo.setName("Similar Triangles");
            panelTwo.add(viewn);
            panelTwo.add(viewn.getTablePanel(), "South");
                  viewn.addMouseMotionListener(
            new MouseMotionListener() { //anonymous inner class
                //handle mouse drag event
                 public void mouseMoved(MouseEvent e) {
                    System.out.println("Mouse at " + e.getX() +","  + e.getY());
               public void mouseDragged(MouseEvent e) {
                   System.out.println("Dragging: x=" + e.getX() + "; y=" + e.getY());
            panel.add("Similar Triangles", panelTwo);
            JPanel panelThree = new JPanel();
            panelThree.setBackground(Color.white);
            panelThree.setName("Circle Theorem1");
            panel.add("Circle Theorem1", panelThree);
        private JMenuBar getMenuBar() {
            JMenu File = new JMenu("File");
            JSeparator separator1 = new JSeparator();
            JMenuItem Open = new JMenuItem("Open");
    //         Open.addActionListener(new java.awt.event.ActionListener() {
    //            public void actionPerformed(java.awt.event.ActionEvent evt) {
    //                openActionPerformed(evt);
            JMenuItem Save = new JMenuItem("Save");
            JMenuItem Print = new JMenuItem("Print");
            JMenuItem Exit = new JMenuItem("Exit");
            Exit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ExitActionPerformed(evt);
            JMenu theorem = new JMenu("Theorem");
            ActionListener l = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    JMenuItem item = (JMenuItem)e.getSource();
                    String name = item.getActionCommand();
                    cards.show(panel, name);
            Component[] c = panel.getComponents();
            for(int j = 0; j < panel.getComponentCount(); j++) {
                String name = c[j].getName();
                JMenuItem item = new JMenuItem(name);
                item.setActionCommand(name);
                item.addActionListener(l);
                theorem.add(item);
            JMenuBar menuBar = new JMenuBar();
            JMenuBar menuBar1 = new JMenuBar();
            menuBar.add(File);
            File.add(Open);
            File.add(separator1);
            File.add(Save);
            File.add(Print);       
            File.add(Exit);
            menuBar.add(theorem);
            return menuBar;
    //    private void openActionPerformed(java.awt.event.ActionEvent evt) {
    //        FileDialog fileDialog = new FileDialog(this, "Open...", FileDialog.LOAD);
    //        fileDialog.show();
    //        if (fileDialog.getFile() == null)
    //            return;
    //        fileName = fileDialog.getDirectory() + File.separator + fileDialog.getFile();
    //        FileInputStream fis = null;
    //        String str = null;
    //        try {
    //            fis = new FileInputStream(fileName);
    //            int size = fis.available();
    //            byte[] bytes = new byte [size];
    //            fis.read(bytes);
    //            str = new String(bytes);
    //        } catch (IOException e) {
    //        } finally {
    //            try {
    //                fis.close();
    //            } catch (IOException e2) {
    //        if (str != null)
    //            textBox.setText(str);
        private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            System.exit(0);
        public static void main(String[] args) {
            new Geometry();
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.text.NumberFormat;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.DefaultTableCellRenderer;
    public class Triangle
    public Triangle()
    TriangleModel tri = new TriangleModel(175,100,175,250,325,250);
    TriangleView view = new TriangleView(tri);
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(view.getUIPanel(), "North");
    f.getContentPane().add(view);
    f.getContentPane().add(view.getTablePanel(), "South");
    f.setSize(500,500);
    f.setLocation(200,200);
    f.setVisible(true);
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.event.MouseEvent;
    import javax.swing.JTable;
    import javax.swing.event.MouseInputAdapter;
    * TriangleControl.java
    * Created on 06 February 2005, 01:19
    * @author  Rahindra Naidoo
    public class TriangleControl extends MouseInputAdapter
        TriangleView view;
        TriangleModel model;
        Point start;
        boolean dragging, altering;
        Rectangle lineLens;            // used for line selection
        public TriangleControl(TriangleView tv)
            view = tv;
            model = view.getModel();
            dragging = altering = false;
            lineLens = new Rectangle(0, 0, 6, 6);
        public void mousePressed(MouseEvent e)
            Point p = e.getPoint();
            lineLens.setLocation(p.x - 3, p.y - 3);
            // are we over a line
            if(model.isLineSelected(lineLens))
                start = p;
                altering = true;
            // or are we within the triangle
            else if(model.contains(p))
                start = p;
                dragging = true;
        public void mouseReleased(MouseEvent e)
            altering = false;
            dragging = false;
            view.getCentroidLabel().setText("centroid location: " +
                                             model.findCentroid());
            view.repaint();  // for the construction lines
        public void mouseDragged(MouseEvent e)
            Point p = e.getPoint();
            if(altering)
                int x = p.x - start.x;
                int y = p.y - start.y;
                model.moveSide(x, y, p);
                updateTable();
                view.repaint();
                start = p;
            else if(dragging)
                int x = p.x - start.x;
                int y = p.y - start.y;
                model.translate(x, y);
                view.repaint();
                start = p;
        private void updateTable()
            String[] lengths = model.getLengths();
            String[] squares = model.getSquares();
            String[] angles  = model.getAngles();
            JTable table = view.getTable();
            for(int j = 0; j < angles.length; j++)
                table.setValueAt(lengths[j], 1, j + 1);
                table.setValueAt(squares[j], 2, j + 1);
                table.setValueAt(angles[j],  3, j + 1);
            view.getCentroidLabel().setText("centroid location: " +
                                             model.findCentroid());
    * TriangleModel.java
    * Created on 06 February 2005, 01:18
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.text.NumberFormat;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.DefaultTableCellRenderer;
    * @author  Rahindra Naidoo
    public class TriangleModel                      //  (x1, y1)
    {                                         //      |\
        static final int SIDES = 3;         //      | \
        private int cx, cy;                  //      |  \
        Polygon triangle;                     //      |_ _\ (x3, y3)
        int selectedIndex;                   //  (x2, y2)
        NumberFormat nf;
        Line2D[] medians;
        Point2D centroid;
        public TriangleModel(int x1, int y1, int x2, int y2, int x3, int y3)
            int[] x = new int[] { x1, x2, x3 };
            int[] y = new int[] { y1, y2, y3 };
            triangle = new Polygon(x, y, SIDES);
            nf = NumberFormat.getNumberInstance();
            nf.setMaximumFractionDigits(1);
        public boolean contains(Point p)
            // Polygon.contains doesn't work well enough
            return (new Area(triangle)).contains(p);
        public boolean isLineSelected(Rectangle r)
            Line2D line = new Line2D.Double();
            for(int j = 0; j < SIDES; j++)
                int[] x = triangle.xpoints;
                int[] y = triangle.ypoints;
                int x1 = x[j];
                int y1 = y[j];
                int x2 = x[(j + 1) % SIDES];
                int y2 = y[(j + 1) % SIDES];
                line.setLine(x1, y1, x2, y2);
                if(line.intersects(r))
                    selectedIndex = j;
                    return true;
            selectedIndex = -1;
            return false;
         * Only works for right triangle with right angle at (x2, y2)
        public void moveSide(int dx, int dy, Point p)
            int[] x = triangle.xpoints;
            int[] y = triangle.ypoints;
            switch(selectedIndex)
                case 0:
                    x[0] += dx;
                    x[1] += dx;
                    break;
                case 1:
                    y[1] += dy;
                    y[2] += dy;
                    break;
                case 2:
                    double rise  = y[2] - y[0];
                    double run   = x[2] - x[0];
                    double slope = rise/run;
                    // rise / run == (y[2] - p.y) / (x[2] - p.x)
                    x[2] = p.x + (int)((y[2] - p.y) / slope);
                    // rise / run == (p.y - y[0]) / (p.x - x[0])
                    y[0] = p.y - (int)((p.x - x[0]) * slope);
        public void translate(int dx, int dy)
            triangle.translate(dx, dy);
        public Polygon getTriangle()
            return triangle;
        public String findCentroid()
            int[] x = triangle.xpoints;
            int[] y = triangle.ypoints;
            // construct the medians defined as the line from
            // any vertex to the midpoint of the opposite line
            medians = new Line2D[x.length];
            for(int j = 0; j < x.length; j++)
                int next = (j + 1) % x.length;
                int last = (j + 2) % x.length;
                Point2D vertex = new Point2D.Double(x[j], y[j]);
                // get midpoint of line opposite vertex
                double dx = ((double)x[last] - x[next])/2;
                double dy = ((double)y[last] - y[next])/2;
                Point2D oppLineCenter = new Point2D.Double(x[next] + dx,
                                                           y[next] + dy);
                medians[j] = new Line2D.Double(vertex, oppLineCenter);
            // centroid is located on any median 2/3 the way from the
            // vertex (P1) to the midpoint (P2) on the opposite side
            double[] lengths = getSideLengths();
            double dx = (medians[0].getX2() - medians[0].getX1())*2/3;
            double dy = (medians[0].getY2() - medians[0].getY1())*2/3;
            double px = medians[0].getX1() + dx;
            double py = medians[0].getY1() + dy;
            //System.out.println("px = " + nf.format(px) +
            //                 "\tpy = " + nf.format(py));
            centroid = new Point2D.Double(px, py);
            return "(" + nf.format(px) + ",  " + nf.format(py) + ")";
        public String[] getAngles()
            double[] lengths = getSideLengths();
            String[] vertices = new String[lengths.length];
            for(int j = 0; j < lengths.length; j++)
                int opp  = (j + 1) % lengths.length;
                int last = (j + 2) % lengths.length;
                double top = lengths[j] * lengths[j] +
                             lengths[last] * lengths[last] -
                             lengths[opp] * lengths[opp];
                double divisor = 2 * lengths[j] * lengths[last];
                double vertex = Math.acos(top / divisor);
                vertices[j] = nf.format(Math.toDegrees(vertex));
            return vertices;
        public String[] getLengths()
            double[] lengths = getSideLengths();
            String[] lengthStrs = new String[lengths.length];
            for(int j = 0; j < lengthStrs.length; j++)
                lengthStrs[j] = nf.format(lengths[j]);
            return lengthStrs;
        public String[] getSquares()
            double[] lengths = getSideLengths();
            String[] squareStrs = new String[lengths.length];
            for(int j = 0; j < squareStrs.length; j++)
                squareStrs[j] = nf.format(lengths[j] * lengths[j]);
            return squareStrs;
        private double[] getSideLengths()
            int[] x = triangle.xpoints;
            int[] y = triangle.ypoints;
            double[] lengths = new double[SIDES];
            for(int j = 0; j < SIDES; j++)
                int next = (j + 1) % SIDES;
                lengths[j] = Point.distance(x[j], y[j], x[next], y[next]);
            return lengths;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.text.NumberFormat;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.DefaultTableCellRenderer;
    * TriangleView.java
    * Created on 06 February 2005, 01:21
    public class TriangleView extends JPanel
        private TriangleModel model;
        private Polygon triangle;
        private JTable table;
        private JLabel centroidLabel;
        private boolean showConstruction;
        TriangleControl control;
        public TriangleView(TriangleModel model)
            this.model = model;
            triangle = model.getTriangle();
            showConstruction = false;
            control = new TriangleControl(this);
            addMouseListener(control);
            addMouseMotionListener(control);
        public void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.draw(triangle);
            if(model.medians == null)
                centroidLabel.setText("centroid location: " + model.findCentroid());
            // draw medians and centroid point
            if(showConstruction && !control.dragging)
                g2.setPaint(Color.red);
                for(int j = 0; j < 3; j++)
                    g2.draw(model.medians[j]);
                g2.setPaint(Color.blue);
                g2.fill(new Ellipse2D.Double(model.centroid.getX() - 2,
                                             model.centroid.getY() - 2, 4, 4));
        public TriangleModel getModel()
            return model;
        public JTable getTable()
            return table;
        public JLabel getCentroidLabel()
            return centroidLabel;
        public JPanel getUIPanel()
            JCheckBox showCon = new JCheckBox("show construction");
            showCon.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    boolean state = ((JCheckBox)e.getSource()).isSelected();
                    showConstruction = state;
                    repaint();
            JPanel panel = new JPanel();
            panel.add(showCon);
            return panel;
        public JPanel getTablePanel()
            String[] headers = new String[] { "", "", "", "" };
            // row and column data labels
            String[] rowHeaders = {
                "sides", "lengths", "squares", "angles", "degrees"
            String[] sidesRow = { "vertical", "horizontal", "hypotenuse" };
            String[] anglesRow = { "hyp to ver", "ver to hor", "hor to hyp" };
            // collect data from model
            String[] angles  = model.getAngles();
            String[] lengths = model.getLengths();
            String[] squares = model.getSquares();
            String[][] allData = { sidesRow, lengths, squares, anglesRow, angles };
            int rows = 5;
            int cols = 4;
            Object[][] data = new Object[rows][cols];
            for(int row = 0; row < rows; row++)
                data[row][0] = rowHeaders[row];
                for(int col = 1; col < cols; col++)
                    data[row][col] = allData[row][col - 1];
            table = new JTable(data, headers)
                public boolean isCellEditable(int row, int col)
                    return false;
            DefaultTableCellRenderer renderer =
                (DefaultTableCellRenderer)table.getDefaultRenderer(String.class);
            renderer.setHorizontalAlignment(JLabel.CENTER);
            centroidLabel = new JLabel("centroid location:  ", JLabel.CENTER);
            Dimension d = centroidLabel.getPreferredSize();
            d.height = table.getRowHeight();
            centroidLabel.setPreferredSize(d);
            JPanel panel = new JPanel(new BorderLayout());
            panel.setBorder(BorderFactory.createTitledBorder("triangle data"));
            panel.add(table);
            panel.add(centroidLabel, "South");
            return panel;
    }PLEASE HELP ME TO LABEL THE TRIANGLE AND CHANGE THE VALUES OF THE JTABLE - to SHOW ASquare b Square and C square as well as a label on the bottom of the screen to show A^2 + B^2 = C^2 ...
    ThANKS

        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            g2.drawPolygon(triangle);
            // label the triangle
            String[] lengths = model.getLengths();
            String[] squares = model.getSquares();
            String[] angles  = model.getAngles();
            int[] x = triangle.xpoints;
            int[] y = triangle.ypoints;
            for(int j = 0; j < x.length; j++) {
                Point2D vertex = new Point2D.Double(x[j], y[j]);
                int next = (j + 0) % x.length;
                int last = (j + 1) % x.length;
                double dx = ((double)x[last] - x[next])/2;
                double dy = ((double)y[last] - y[next])/2;
                Point2D center = new Point2D.Double(x[next] + dx, y[next] + dy);
                g2.drawString(angles[j],(int)vertex.getX(),(int)vertex.getY());
                g2.drawString(lengths[j],(int)center.getX(),(int)center.getY());
            g2.drawString(squares[0],100, getHeight());
            g2.drawString(" + "+squares[1],150, getHeight());
            g2.drawString(" = "+squares[2],200, getHeight());
            if(model.medians == null)
                centroidLabel.setText("centroid location: " + model.findCentroid());
            // draw medians and centroid point
            if(showConstruction && !control.dragging) {
                g2.setPaint(Color.red);
                for(int j = 0; j < 3; j++)
                    g2.draw(model.medians[j]);
                g2.setPaint(Color.blue);
                g2.fill(new Ellipse2D.Double(model.centroid.getX() - 2,
                        model.centroid.getY() - 2, 4, 4));
        }

  • Label display issue in Tree component when it is having vertical scrollbar

    I am using tree component as dropdown factory for combo box. When i open dropdown, it doesn't have vertical scrollbar and all the root nodes are getting displayed correctly(in closed mode). Now if i try to open any node, i am getting vertical scrollbar as the child nodes are more. Now the problem is if scroll down, some of the nodes(labels) are not getting displayed but i am able to see the icon. If i keep on scrolling bottom to top and top to bottom, some of the nodes are showing labels and some are not(It is inconsistant).
    I have not used any custom item renderer for tree control. I used my custom dataDescriptor which i have implemented from ITreeDataDescriptor. Also I tried extending DefalutDataDescriptor, but no luck.

    Does it work if the tree is not in a combobox?

  • How to make the labels vertical in a horizonal bar chart?

    Hi,
    I am using CF 9.  I have a horizontal bar chart.  How can I make the labels on the Y-Axis display horizontally.  Right now they are vertical and sort of sideways.
    Below is a snipept from my <cfchart>.  Everything is working, I just want the labels to display horizontally.  How can I do this?
    <cfchart
                              format="png"
                              chartheight="310" chartwidth="530" foregroundcolor="##000000"
                              show3d="false"
                              scalefrom="0" scaleto="14"
                              showlegend="no"
                              showxgridlines="yes"
                              showygridlines="no"
                              showborder="no"
                              style="#elementStyle#" >
                              <cfchartseries type="horizontalbar" paintstyle="shade"">
                              </cfchartseries>
    </cfchart>
    Thanks...

    When you open the default New Tab page - about:newtab - which has the Tiles and a Search Bar, the "focus" is in the Search Bar. You could change a hidden setting to have a blank page when you open a new tab if that's what you want - that will have the "focus" in the Location Bar . URL Bar.
    Type '''about:config''' in the URL bar and hit Enter.
    ''Accept the warning''
    Search field at the top to filter with this - '''browser.newtab.url'''
    Right-click the preference that appears below, and select '''Modify'''.
    Insert '''about:blank''' for the new string value.

Maybe you are looking for