Urgent... Adding focus listeners to labels..

Hi,
Is it possible to handle focus events on labels? I tried to add a FocusListener to a label, but the labels aren't receiving any focus. Is there any way to achieve this? I was trying to build a table component with each table cell being represented by a label. The user should be able to navigate across the table cells using arrow keys. Is there any other alternative than using a label?
regards,
Anand

hi!
from jdk1.4 in java.awt.component class has setFocusable(boolean focusable) method. use this to set the label focusable.
i hopen this can help you
:)

Similar Messages

  • Very Urgent?Facing Problems With Labels

    Hi All,
    It's Very Urgent,In My VC Application
    Label Have More Than 15 Characters
    I PUT Label Layout  To Long Label.
    My Label Name  online assignement date
    But Even Put Long Label, online ***.......
    Please Resolve The Problem ASAP.
    Thanks
    SubbaRao Chinta

    Hi Subbu,
    I told u already its an Know issue with Flex compiler ,Even u set the label to long label it will show u only short label.
    This issue is fixed with Flex2 compiler.
    Use Flex2 compiler for ur application then it will dispaly the total label u want display.
    Regards,
    Govindu

  • Problem while adding both Key And Focus Listeners to JTextField

    Hi!
    I have something peculiar while adding Key and Focus Listener to JTextField. Suppose i add just Key Listener then everything's fine and i could keep track of keys being pressed. But as soon as i add a Focus Listener to it with the code to select full text in focusGained() method, it starts reponding wrongly to arrow keys pressed and does not perform desired actions. For let arrow key it moves caret by one for the first time after that it does not resond to that unless caret is changed by using mouse. If right arrow key is pressed the it moves the caret to last position from wherever it is. For UP and DOWN it selects the full text(This should be done when it gets focus)
    public void focusGained(FocusEvent fe)
    setCaretPosition(0);
    moveCaretPosition(getDocument().getLength());
    Can someone help me out on this?
    thanks and regards,
    Amit.

    None of those things will cause your JFrame to resize itself. And this is probably a good thing, because your JFrame shouldn't change size once you have created it. Why not create your JPanel so that it has enough space for you to add the component later? Or why not just add the component to start with and then enable it or make it editable when you decide that's necessary?

  • Urgent! focus problem

    I have panel with two buttons(b1,b2). How could I set focus on b2(or b1) when I add the panel to the frame.
    I have tried b2.requestFocus(), it seems not working until I make a mouse click.
    Please help me.Thanks.

    public void goToButton(final JComponent comp){
    SwingUtilities.invokeLater(new Runnable() {
         public void run() {
              comp.setRequestFocusEnabled(true);
              comp.requestFocus();
    Call this method when panel is added in frame. comp is
    the button.This idea is good, if you show the frame immediately after it is instantiated - but if you do it later, this run method will be processed before the frame is shown with the same result - the focus is not transferred to the component which requests it.
    Another thing - if you want to use comp within the run() method you will have to declare it final; the above code would not compile as posted.
    greetings Marsian

  • Urgent assistance needed on textfields/labels please!!

    I have been trying for days to add labels and textFields to my applet and can only manage to display one.
    My assignment instructions suggest I use makeTextField method and call the setEditable method from the makeTextField method to avoid repetition of code.
    The following is my code...I must have this done in the next couple of days so if someone could please please give me some assistance it would be really appreciated....also, thoughts on my layout would be great as well...i cant seem to set up my buttons in the correct order.
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.Applet;
    public class Registry4b extends Applet implements ActionListener {
    public void init() {
    backgroundColor = new Color(200,255,255);
    this.setLayout(new FlowLayout(FlowLayout.CENTER,4,1));
    makeButtons();
    row1 = makePanel(new FlowLayout(FlowLayout.LEFT,4,2),backgroundColor);
    row1.add(clearB);
    row1.add(studFindB);
    row1.add(studForB);
    row1.add(courB);
    row2 = makePanel(new FlowLayout(FlowLayout.LEFT,4,2),backgroundColor);
    row2.add(studBackB);
    row2.add(courFindB);
    row2.add(courForB);
    row2.add(studB);
    row3 = makePanel(new FlowLayout(FlowLayout.LEFT,4,2),backgroundColor);
    row3.add(courBackB);
    add(row1);
    add(row2);
    add(row3);
    Panel p = new Panel(new BorderLayout());
    Label studID = new Label("STUDENT ID");
    TextField entry = new TextField(" ");
    p.add(studID,BorderLayout.WEST);
    p.add(entry,BorderLayout.CENTER);
    Label firstTF = new Label("FIRST NAME");
    makePanel(new BorderLayout(2,2),backgroundColor);
    add("West",courBackB);
    add("East",studB);
    makePanel(new BorderLayout(2,2),backgroundColor);
    add("North",p);
    add("South",courForB);
    makePanel(new BorderLayout(2,2),backgroundColor);
    add("North",courFindB);
    add("South",studBackB);
    makePanel(new BorderLayout(2,2),backgroundColor);
    add("West",p);
    add("East",studForB);
    setBackground(backgroundColor);
    clearB.addActionListener(this);
    courBackB.addActionListener(this);
    studB.addActionListener(this);
    courForB.addActionListener(this);
    courFindB.addActionListener(this);
    studBackB.addActionListener(this);
    courB.addActionListener(this);
    studForB.addActionListener(this);
    studFindB.addActionListener(this);
    private Label makeLabel(String label) {
    Label label1 = new Label(label,Label.RIGHT);
    label1.setFont(new Font("Courier",Font.BOLD,10));
    return label1;
    public void start() {
    appletWidth = 8*4+row1.getSize().width;
    appletHeight = 8*(2+courBackB.getSize().height);
    public void paint(Graphics g) {
    setSize(appletWidth,appletHeight);
    validate();
    public void actionPerformed(ActionEvent e) {
    String s = (String)e.getActionCommand();
    private Button makeButton(String label, Color color, Font font) {
    Button b = new Button(label);
    b.setBackground(color);
    b.setFont(font);
    return b;
    private Panel makePanel(LayoutManager lm, Color c) {
    Panel p = new Panel();
    p.setLayout(lm);
    p.setBackground(c);
    return p;
    private void makeButtons() {
    Font f = new Font("Courier", Font.BOLD, 10);
    Color grey = new Color(255,100,100);
    clearB = makeButton("CLEAR",grey,f);
    studB = makeButton(" STUDENTS ",grey,f);
    studForB = makeButton("->",grey,f);
    studFindB = makeButton("FIND",grey,f);
    courFindB = makeButton("FIND",grey,f);
    studBackB = makeButton("<-",grey,f);
    courB = makeButton(" COURSES ",grey,f);
    courBackB = makeButton("<-",grey,f);
    courForB = makeButton("->",grey,f);
    TextField addressTF = new TextField("ADDRESS", 10);
    static final String initialString = " ";
    String Filler = " ";
    Panel row1, row2, row3, p1;
    int appletWidth, appletHeight;
    Button clearB, studForB, studFindB, courFindB,
    studBackB,courB, courBackB, studB, courForB;
    Color backgroundColor;
    thanks in advance for anything someone can do for me

    I haven't tried your code, but since you use a layout manager, you shouldnt need to think about setting the size for the applet.
    And I think when you call the method makePanel the last 4 times, you want to use the returned panel to add your components on. Right now you add everything directly to the panel and never use the panels you create.
    And you also reuse some of your components more than once (like e.g. courBackB). You need to create a new button everytime, otherwise if you try to add the same button twice, the second one will not be displayed.
    Try to add the components one by one and check it is displayed before you add the next one.
    If you want to check what components and their sizes etc, you have on your applet, here is a little trick. Get the focus on your applet and press ctrl+shift+F1. If you run the applet in a browser, you will get something in the java console that displays all your GUI components and a description of them. So
    It might help you.
    Also take a look of the Java Tutorial for the AWT. You can download it from
         http://java.sun.com/docs/books/tutorial/information/download.html
    called tut-OLDui.zip.

  • Adding a canvas and label to a frame

    Actually the problem is that we have created a frame.
    And in that frame we are adding a canvas and drawing image on canvas.
    Now if we add a label to that frame after adding the canvas then the image is not drawn and if we add canvas after adding label to frame then the label is not shown, only image is shown.
    /****CASE 1***************/
    Create a frame
    Add canvas
    Add label
    frame.setvisible(true)
    After this, paint function is called and
    in the paint function, we are calling a native function which is taking canvas as argument and drawing some images
    Result: Only label is displayed
    /****CASE 2***************/
    Create a frame
    Add label
    Add canvas
    frame.setvisible(true)
    After this, paint function is called and
    in the paint function, we are calling a native function which is taking canvas as argument and drawing some images
    Result: Only image is displayed
    Thanks
    Arun

    Hey!!
    Even I am also facing some similar sort of a problem.
    I was trying write a program using JOGL , in that if I draw a rectangle and I click anywhere on the rectangle in the frame ,it should show me the x,y coordinates. Since I am not using applet,so I need to place both the things on the same frame. Can Anybody help....

  • URGENT HELP REQUIRED _ Creating Labels for Triangle

    Hi everyone... the code below is my application - Pythagoras Theorem.. or rather displaying it.. But i have not been able to get the Vertex of the triangle Labelled as A B C... I need to do that and change the Triangle Table data to A B C insted of Horizontal Vertical and Hypotenuise and as the triangle is stretched on screen A B And C keep moving as well ...
    Besides i need to Show this in the tabel
    - Values of A ^ 2 , B^2 and C ^2 as welll as a row showing A^2+B^2 = C^2
    the code is as follows..
    This is the main class called 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;
    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 ---- Also does any one know how to draw a Triangle on a screen which can be controlled by a JSlider such that as and whenits incremented the triangle increase and vice versa... I need to prove Similarity in triangles using A Jslider that controls one triangle while the other triangle is Still on screen

    Sharan,
    The code given was part of the assignment and you are supposed to make the changes for your part right?
    Please give details of what you have done so far and not expect us to do your assignment for you. We'll be glad to help answer questions and point to the right direction, but giving us the entire assignment and saying, very nicely I might add, "Please do it for me." Just seems to make a mockery of the hours, days, and years that many of us has spent earning our degrees and learning our skills.
    Work on it and ask specific questions with examples of what you have done and you'll get a much better response.

  • Very Urgent--Adding Header condition amount in Net order value of PO

    Dear friends,
    Our client has following requirement.
    ---In Purchase order ,Header conditions related to delivery costs are using.
    --Currently when we add the header condition,that amount is not adding to the Net order value and not adding to the total value in the PO print document.But proportionaly distributing to the line items.
    --Because of this two problems one is not adding to net order so not considered for release strategy,secondas it is not adding in the net order value,header condition amount also is not coming in the total value in the print out.
    --Currently, this header amount is splitting and posting seperate line item for GR/IR clearing act in MIGO and MIRO..
    I have removed the Statistical tick and accrual tick in IMG, then header amount is adding to the Net order value and adding in the total value in the PO print. But in MIGO/MIRO, This amount is adding to the GR/IR clearing act ,instead of seperate GR/IR line item in MIGO/MIRO documents, But client wants the postings shall be made similar to previous one.
    I have checked with removing only Stastical key and not removing the accrual key.But header condition is not adding to Net order value. I have searched for User exits/BAdis,suitable are not found.
    How the Header condition amount can be added to the Net order value without removing the Statistical key in IMG.Are there any User exit/BAdis,
    Please suggest.
    Regards,
    Dayanand

    Dear Sairam,
    Thanks for your reply.
    Asper your suggestions i tried as follows.
    1) We have got condition types like surcharges/discounts before "Net inc dis"
        and Delivery costs/accruals/frieghts after "Net inc dis".
    2) My requirement is that whatever conditions types after Net inc dis like Del costs/Frieghts are not included in Net order value in PO,so amount is not included in Release strategy and print.Currently this amount is coming as seperate line itemGR/IR Clearing account in MIGO/MIRO.
    3) Asper your suggestion,i tried with Surcharge  condition existing before "Net inc Disc"--This is a header condition(Cond.cat is Insurance),but stastical tick is not there in Scema. I tried as it is ,amount is adding in Net order value.But seperate line item for this amount is not coming in MIGO/MIRO
    4) When i ticked the accrual key and statistical tick and added Accrual-FR1,then PO created ,amount is not adding in Net order value.
    5) When i removed only Stastical tick only even though amount is not adding.
    6) When i removed the Accrual tick also i.e both the ticks then only amount is adding in Net order value.But Line item of the header condition is not dispalying as a seperate line item in MIGO/MIRO
    For these Header conditions ,seperate line item shall come ,at the same time amount shall add in Net order Vaue for the purpose of including in the amount for Release strategy and print.
    Please suggest how to do it.
    Regards,
    Dayanand

  • URGENT: Wrong Info on Return Labels for Exchange Orders.

    Hi! SAP Gurus
    Exchange orders are being shipped with labels attached on the box that says DO not return defective part and because of this the customer will either dispose of the part, and therefore the business will not receive the defective back and we cannot bill since we told them not to return the part.
    Thanx in advance
    Sushmitha

    Dear Sushmitha
    This can be done in multiple ways, depending mainly on statutory obligations.
    One is Invoice in full and do reject cycle (credit memo...), if customer agrees
    2nd is use movement type 451 - returns from customer and invoice for net sales quantity only and then close the sales order.
    Regards
    Jitesh

  • Best practices for adding CLICK listeners to complicated menus?

    OK, I’m gonna wear out my welcome but here’s my last question of the day:
    I’ve got a project that is essentially a large collection of menus, some buttons common across multiple screens, others unique. The following link is the work in progress, most of the complexity is in the “Star Action Items and Forms” area (btw: the audio in the launch presentation is just a placeholder track, I know we can't use it):
    http://www.appliedcd.com/Be-A-star/Be-A-star.html
    To deal with the large number buttons my timeline simply has the following for every menu frame:
    stop();
    initFrame();
    The initFrame() function then has a list of frames and activates the buttons appearing on each screen, a very simplified example follows. In this example commonButtons span all 3 menus, semiCommonButtons span menu 2 and 3, button1A, button2A, etc… are unique per menu.:
    function initFrame():void {
         var myFrame:String = this.currentLabel;
         commonButton1.addEventListener(MouseEvent.CLICK,onInternalLink);
         commonButton2.addEventListener(MouseEvent.CLICK,onInternalLink);
         commonButton3.addEventListener(MouseEvent.CLICK,onInternalLink);
         switch(myFrame) {
              case "menu1":
                   button1A.addEventListener(MouseEvent.CLICK,onInternalLink);
                   button1B.addEventListener(MouseEvent.CLICK,onInternalLink);
                   button1C.addEventListener(MouseEvent.CLICK,onInternalLink);
              break;
              case "menu2":
                   semiCommonButton1.addEventListener(MouseEvent.CLICK,onInternalLink);
                   semiCommonButton2.addEventListener(MouseEvent.CLICK,onInternalLink);
                   semiCommonButton3.addEventListener(MouseEvent.CLICK,onInternalLink);
                   button2A.addEventListener(MouseEvent.CLICK,onInternalLink);
                   button2B.addEventListener(MouseEvent.CLICK,onInternalLink);
                   button2C.addEventListener(MouseEvent.CLICK,onInternalLink);
              break;
              case "menu3":
                   button3A.addEventListener(MouseEvent.CLICK,onInternalLink);
                   button3B.addEventListener(MouseEvent.CLICK,onInternalLink);
                   button3C.addEventListener(MouseEvent.CLICK,onInternalLink);
              break;
    The way the project was designed, I “thought” menu3 would only be accessible through menu2, thus guaranteeing that the semiCommonButtons would get initialized, but I forgot the functionality of my back button could jump the user directly from menu1 to menu3. The solution is simple, initialize every button on every navigation  target, however, is this really the best way to initialize a bunch of buttons? Another possible approach would be to have an array of button instance names and a function that said: if instance XYZ exists, add listener, then simply loop through the array on every nav target. Anyone with more experience have advice on best practices in this situation?

    Hmmmm just run a test on this whereby I added the above snippet to my master page. I then publish a major version. I can see that every (Welcome) custom page layout has this data widget working, providing I add the div to the page..  
    I wonder if the reason I can't add the snippet  directly  to an individual custom layout page is a bug or am I doing something incorrectly?
    Daniel

  • URGENT: Regaining Focus

    Hello everybody!
    To get some print screen functionality in Oracle Forms 9i (as the PRINT built-in has proved problematic), I have created a 'Print' button using the HTMLbeforeForm= parameter in formsweb.cfg.
    Works like a charm! But... how do I get the focus back to the exact item I was in prior to pressing the button? Currently, I have to click in the java console area to regain the cursor.
    Presumably, it's some Javascript?
    We're using Sun's JRE and IE 6.
    Many thanks

    Well I dont have a solution, but this is what I tried and the error that I received. Maybe this will lead you down a better path... I used IE and received this javascript debugging error. I was trying to give the first object tag in the HTML focus. I also tried obj[1] which would be the second object tag and the actual form.fmx. Didnt work. Maybe Im using the wrong HTML tag to get focus? If you view source from the browser you will see that there are two html "object" tags. There's not much else to give focus too? I am using webutiljini.htm.
    HTMLbeforeForm=<input Name="Press Me" value="Press Me" type=button onClick="var obj = document.getElementsByTagName('object'); obj[0].focus()"></input>
    The error message was..
    "Cant move focus to the control because the object is invisible, not enabled, or of a type that does not accept the focus."
    Im guessing that an object tag doesnt accept focus. :)

  • Urgent : Adding Compounding Attribute 0CO_AREA

    Hi,
    When I added 0CO_AREA as a COMPOUNDING attribute of 0WBS_ELEMT,
    Following is the error message :-
    <b> InfoObject 0WBS_ELEMT is referenced from 0CRM_MKTELE, compounding cannot be changed</b>
    Diagnosis
    The InfoObject 0WBS_ELEMT is referenced by InfoObject 0CRM_MKTELE. InfoObjects have been deleted or inserted from the compound of InfoObject 0WBS_ELEMT. The compounds of InfoObject and referenced InfoObject must, however, concur with each other.
    System response
    InfoObject 0WBS_ELEMT can only be activated if InfoObject 0CRM_MKTELE is activated at the same time.
    Procedure
    Include all the InfoObjects, that reference InfoObject 0WBS_ELEMT, together in the editing and activate them likewise.
    Otherwise, you can only change the compounding of InfoObject 0WBS_ELEMT if there are no more other InfoObjects that reference InfoObject 0WBS_ELEMT.

    Hi John,
    Please see OSS note 184948 (Compound Infoobjects to 0SOURSYSTEM). Though this takes the example of 0SOURSYSTEM added as a Compound InfoObject, but the same applies in your case too. The solution mentioned is:
    "In this case, characteristic 'XYZ' must also be compounded to 0SOURSYSTEM.Characteristic 'XYZ' must be activated together with characteristic 'ABC'.
    If you have to change dependent characteristics also, all characteristics must be activated together with characteristic 'ABC'.Otherwise, the consistency check uses the active version of the dependent characteristics and reports errors.In the initial screen of InfoObject maintenance select radio button 'Free selection of InfoObjects'.In the dialog box, select all characteristics you want to activate together.Select all characteristics on the following overview screen and press 'Activate'.If you are already on the detailed screen of InfoObject maintenance and include the other InfoObjects in the maintenance using pushbutton 'Other InfoObject' then for activation you must go back to the overview screen and select and activate all InfoObjects there.This procedure is necessary since activating on the detailed screen is for the currently selected InfoObject (and dependent objects) only but not for all InfoObjects visible in the overview list.If you want to activate several InfoObjects together, then you should always do this from the overview list."
    Hope this helps...

  • Problems with adding spaces into a label

    Dear BSP-Fans,
    I'm creating in a internal Table the lines I like to print out. Because the table could bee very big I'm trying to shift some Values by a few space right.
    If I look into my internal Table, before she is show as as BSP these spaces are in there. But on the BSP-Site they are not shown and all value do have the same horizontal aligment.
    Here is just a sample of my coding:
    <%
    loop at controller->pt_quali_list into ls_quali_list.
    %>
    <htmlb:radioButtonGroup id = "<%= ls_quali_list-q_objid %>"
    mode = "LOGICAL_GROUPING" >
    <htmlb:gridLayoutCell columnIndex = "1"
    rowIndex = "<%= row_index %>"
    style = "<%= style %>"
    <htmlb:label for = "<%= ls_quali_list-q_objid %>"
    text = "<%= ls_quali_list-stext %>" />
    </htmlb:gridLayoutCell>
    <%
    endloop
    %>
    Any suggestions from you?
    Thank you very much.
    Philipp

    Dear Philipp,
    Here is a very simple example showing you how to add spaces:
    <%@page language="abap"%>
    <%@extension name="htmlb" prefix="htmlb"%>
    <htmlb:content design="design2003"   >
      <htmlb:page title = "test ">
        <htmlb:form>
       <htmlb:gridLayout rowSize="5"
                      columnSize="1">
    <%
    DATA: row_index type Int4,
          text type String.
    DO 5 TIMES.
    %>
      <htmlb:gridLayoutCell columnIndex = "1"
                            rowIndex = "<%= row_index %>">
    <%  MOVE row_index to text.
        CONCATENATE '   ' text into text. %>
                    <htmlb:label for = "<%= row_index %>"
                                 text = "<%raw= text %>"
                                 encode = "false" />
       </htmlb:gridLayoutCell>
    <%
       add 1 to row_index.
    ENDDO.
    %>
        </htmlb:gridLayout>
            </htmlb:form>
      </htmlb:page>
    </htmlb:content>
    So you need to set the encoding parameter to false, and convert all your space characters to the ' ' string.
    I hope it helps you.
    Regards,
    Dezso

  • JavaFx Adding Focus Traversable Keys.  Any Ideas?

    Hallo,
    Since there is currently now way to add other keys to the focus traversable list, I have to create my own method of doing it.  What I want to do is have a single scene, and in that scene I want the enter key to behave  
    the same as a tab key.  But there are a lot of Buttons, TextField, ChoiceBoxes etc.  Therefore Pressing enter key must take me to the next focusable item.  I have really been struggling to find a method that work.  I am really stuck.  Some help would be much appreciated.
    Thank you

    Well there are a few things you can do imo.
    1.  Create KeyEvents for each of your controls.
    2. http://download.java.net/jdk8/jfxdocs/index.html? click Scene, then NODE(for some reason the HTML links do not appear, and the one I had was for "SHAPE 3D").
    focusedpublic final ReadOnlyBooleanProperty focusedPropertyIndicates whether this Node currently has the input focus. To have the input focus, a node must be the Scene's focus owner, and the scene must be in a Stage that is visible and active. See requestFocus() for more information.
    See Also:
    isFocused(), setFocused(boolean)
    Default value:
    false
    focusTraversablepublic final BooleanProperty focusTraversablePropertySpecifies whether this Node should be a part of focus traversal cycle. When this property is true focus can be moved to this Node and from this Node using regular focus traversal keys. On a desktop such keys are usually TAB for moving focus forward andSHIFT+TAB for moving focus backward. When a Scene is created, the system gives focus to a Node whose focusTraversable variable is true and that is eligible to receive the focus, unless the focus had been set explicitly via a call to requestFocus().
    See Also:
    isFocusTraversable(), setFocusTraversable(boolean)
    Default value:
    false
    If you click either property it will brng you to the entire 8000 lines of the code, which I also cannot link for some reason.
    Both will link you to the area of code, and possibly you could edit this yourself.

  • Urgent- Data Merge with 4 labels to a page not working

    I have a csv file that I am attempting to place 4 labels to a page.
    I use the multiple record placement and all records but it only generates the 1st record for all labels.
    What am I doing wrong.

    Have you placed the label four times on your page? If so, that's what you are doing wrong.
    You only place ONE copy of the label in the top left of the page, and InDesign will clone it and work its way through
    your CSV data as it does so.
    Positioning of the labels is done by the margin and separation options in the multiple label dialogue, and you can check
    the output with preview.
    k

Maybe you are looking for