1

I m making desktop app in java swing for dentist. In my app my image is 16 bit tiff gray-scale image.I draw image on JPanel. I want to add or put moveable textarea on myImage. So doctore can write on image and save it.So when doctore open that image next time he/she can easily understand image of patients. I give 1 example of image below.

enter image description here

Jay
  • 1,235
  • 10
  • 28
  • 49
  • @Reimeus thanks for early reply.Actually my problem is that, i give 5 functionality of measurement in myapp like draw straight line, curve line, shape, angle, and grid.when doctore draw something like curve line and it will display on image using mouse dragged event and Array of List of Lines and length of curve line is shown in one label on myapp. now doctore wants to store drawed line in image. so i used Graphics object of my image and store lines in my image. now i want to save or write string in teeth image. So i m thinking about that. and i tried Jtextfield but dont work well for me. – Jay Dec 14 '12 at 13:55
  • *"tried Jtextfield but dont work well for me"* Post an [SSCCE](http://sscce.org/) of your best attempt. See also the `LabelRenderTest` class in [this answer](http://stackoverflow.com/a/5853992/418556) which draws a `JLabel` on an image. – Andrew Thompson Dec 14 '12 at 14:15
  • See also [`ImageJ`](http://stackoverflow.com/tags/imagej/info). – trashgod Dec 14 '12 at 14:20
  • @trashgod . yes u r right. i have also ImageJ software. but i can't understand that how to make textbox as like in imageJ , when i pressed A button of ImageJ software. i attached fig above in which i open in ImageJ and pressed A button and like that. So What happened when i pressed A button in ImageJ or how they are made moveable textbox on Image in ImageJ software? – Jay Dec 15 '12 at 09:45

2 Answers2

2

You have several options:

  • Use a transparent text component in a resizable container, illustrated here.

  • Use @camickr's ComponentResizer, cited here, with a transparent text component.

  • Study an existing implementation, such as ImageJ, cited here, or JHotDraw, cited here.

  • Develop your own implementation using the draggable handles illustrated here.

Although the latter are more flexible, I'd tend to favor the component approaches for ease of implementation.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    thanks for sharing your knowledge. now i m trying to make best moveable text area on Image. – Jay Dec 17 '12 at 07:42
0

I would override paint method of your JPanel (to make it draw the image as background) and add a JTextArea to it as usual. This way, you can create your own Graphics object, call paint, then save your Graphics obj as an image.

public class MyPanel extends JPanel {

    JTextArea myTextArea = new JTextArea();

    public MyPanel {
        // ...
       add(myTextArea, new GridBagConstraints(....));
       // ...
    }

    @Override
    public void paint(Graphics g) {
        g.drawImage(.....);
        super.paint(g);
    }
Slauster
  • 99
  • 1
  • "Swing programs should override `paintComponent()` instead of overriding `paint()`."—[*Painting in AWT and Swing: The Paint Methods*](http://www.oracle.com/technetwork/java/painting-140037.html#callbacks). – trashgod Dec 15 '12 at 12:55