I need to draw some line over my JFrame
I draw them using the paint method. The lines are drawn but the JInternal Frame does not show all the other components, JTextFields, JLabels...
Can please S.O help me?
my code is:
public void paint (Graphics2D g)
g.setColor(Color.black);
cambiaColor cc = new cambiaColor();
Font fo;
fo = new Font ("Arial Unicode MS",Font.BOLD,10);
g.setFont(fo);
java.awt.FontMetrics metric = g.getFontMetrics(g.getFont());
g.drawRect(0,90,450,270);
g.drawRect(0,100,450,60);
int ini = Integer.parseInt(((Object[])((Object[])dec.getDatosControlador())[2])[0].toString())-1;
int fin = Integer.parseInt(((Object[])((Object[])dec.getDatosControlador())[2])[1].toString());
int rowIni = (int)(ini/8);
int rowEnd = (int)(fin/8);
int c=0;
if ((ini != 0) && (fin !=32))
for (int i=rowIni;i<=rowEnd;i++)
if (i>rowIni)
ini = (8*c);
if ((i+1)*8>fin)
g.drawRect((50*(ini%8))+20,(i*63)+95,((50*(fin%8))+20)-((50*(ini%8))+20),63);
else
g.drawRect((50*(ini%8))+20,(i*63)+95,425-((50*(ini%8))+20),63);
c++;
g.setColor(new Color(204,204,204));
g.drawLine(10,10,15+metric.stringWidth("Detectores"),10);
g.drawLine(10,90,15+metric.stringWidth("Grupos"),90);
g.setColor(Color.black);
g.drawString("Detectores",15,10);
g.drawString("Grupos",15,90);
}
Take a look at the RootPane tutorial:
http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html
Specifically at the GlassPane stuff.
The GlassPaneDemo shown there includes some code where the paint method was modified. I think you can use something like that in your code too.
Similar Messages
-
Hello,
Does anyone know if there is a way to draw a line over a JLabel. The scenario is that I have a Jpanel that uses a Gridbaglayout and has an array of JLabels(to display images). I have the need to connect labels and to have the line draw over any labels that it intersects.
I know this can be done if you use the same graphics context to draw the image and the line, but since I need to use JLabels and the graphics context that draws the line is a JPanel's, I have a problem.
Is there a way to draw a line over a JLabel?
Thanks
lonEasiest thing to do would be to override paintChildren like
public void paintChildren(Graphics g) {
super.paintChildren(g);
//paint your line here
}That should do what you want - paint the children first and then draw over them -
Need to draw a line in a screen
I have created a custom screen in screen painter . I need to draw straight line in my screen between two blocks .
Is there any option for that in screen painter?
Thankshi Priya,
Do as Rich as suggested i.e, use Text Field with underscores...
and by the way..
please close this thread
screen in display mode
by marking helpful answers incase if your problem is solved/ Question is answered -
I have 2 panels inside a JFrame and I want to separate the 2 panels using a visible line. How can I draw this line?
You will need to over ride the paint(Graphics g) method.
From there you can use the g.drawLine(startX,startY,endX,endY). So for instance if you had two panels next to each other and the line is a vertical line then you would do something similar to this.
public void paint(Graphics g){
super.paint(g);
int x = this.jPanel1.getWidth();
g.drawLine(x, 0, x, this.getHeight());
}This is probably a good place to start learning java2d
http://java.sun.com/docs/books/tutorial/2d/basic2d/index.html -
I can fake what I need if the path is something like:
But if the path doubles back on itself, such as:
The wipe does not have the desired effect. I would think the appropriate name for what I want would be "Draw". I want the line to be drawn from one end to the other in a specified amount of time.create 2 draw shapes showing as a single coloured line;
one that shows the line from the starting point at the left to the furthest point it extends to the right
the second line starts from the end point of line 1 to the furthest point it extends to the left
add a wipe to line 1, wiping from left to right
add a wipe to line 2, wiping from right to left, which automatically builds after build 1, with no delay
when played back it will look like a single wipe -
Can anyone please help about the parameters that need to be passed corectly.
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
CGColor[] colors = {UIColor.Red.CGColor,UIColor.Green.CGColor};
float[] locations = {0.0f,0.5f,0.5f,1.0f};
CGGradient gradient = new CGGradient(colorSpace,colors,locations);
ColorMessage.FontSize = width;
context.SetLineWidth(width);
context.SaveState();
context.Clip();
context.DrawLinearGradient(gradient,penVertices[0],penVertices[count-1],0);
context.StrokePath();
gradient.Dispose();
colorSpace.Dispose();
context.RestoreState();Wouldn't this be better posted in a developers forum? This forum is for Using an iPad, not writing programs for one.
-
Hey
I've already figured out how to draw dotted lines so that's not the questions
the thing is I only need to draw some lines as dotted, some as dashed and all others just normal..
I figured I could make radiobox to select which line.. then I save that to an array of some sort and then in the paintComponent thing I should make an if to check for array value and change the stoke according to that
so far I've just made my lines dotted like this
http://www.jguru.com/faq/view.jsp?EID=114099
but now everything is dotted.. even the borders around my buttons..
ni my applet I have some buttons which are connected with a line.. I want that line dotted or dashed when the users wants it to.. and only then otherwise just normal lines
I couldn't find anything about that on the google =(done!
now I want to be able to use diffrent line style combinations but it doesn't work
currently it only uses the linestyle that you selected for the first line and then uses that for every line after that too
this is my code
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(lijnKleur);
for (int i = 0; i < Main.XList.size(); i++) {
int j = (i - 1);
int k = (i + 1);
int aantal = 0;
if ((k % 2 == 0) && (i != 0)) {
if (Main.lijnstyleList.get(aantal) == 1){
g2d.setStroke(normaal);
else if (Main.lijnstyleList.get(aantal) == 2){
g2d.setStroke(gestippeld);
else if (Main.lijnstyleList.get(aantal) == 3){
g2d.setStroke(gestreept);
else{
g2d.setStroke(normaal);
int tmpX_oud = Main.XList.get(j) + (Main.breedte / 2);
int tmpY_oud = Main.YList.get(j) + (Main.hoogte / 2);
int tmpX = Main.XList.get(i) + (Main.breedte / 2);
int tmpY = Main.YList.get(i) + (Main.hoogte / 2);
aantal++;
if (tmpY_oud > tmpY){
tmpY = tmpY + (Main.hoogte / 2);
int half = tmpY + (Main.spacing / 2);
if ((tmpY_oud != tmpY) && (tmpX_oud != tmpX)) {
g2d.drawLine(tmpX_oud, tmpY_oud, tmpX_oud, half);
g2d.drawLine(tmpX_oud, half, tmpX, half);
g2d.drawLine(tmpX, half, tmpX, tmpY);
else{
g2d.drawLine(tmpX_oud, tmpY_oud, tmpX, tmpY);
g2d.drawLine(tmpX, tmpY, tmpX - 5, tmpY + 8);
g2d.drawLine(tmpX, tmpY, tmpX + 5, tmpY + 8);
else if (tmpY_oud < tmpY){
tmpY = tmpY - (Main.hoogte / 2);
int half = tmpY - (Main.spacing / 2);
if ((tmpY_oud != tmpY) && (tmpX_oud != tmpX)) {
g2d.drawLine(tmpX_oud, tmpY_oud, tmpX_oud, half);
g2d.drawLine(tmpX_oud, half, tmpX, half);
g2d.drawLine(tmpX, half, tmpX, tmpY);
else{
g2d.drawLine(tmpX_oud, tmpY_oud, tmpX, tmpY);
g2d.drawLine(tmpX, tmpY, tmpX - 5, tmpY - 8);
g2d.drawLine(tmpX, tmpY, tmpX + 5, tmpY - 8);
else {
if (tmpX_oud > tmpX){
tmpX = tmpX + (Main.breedte / 2);
g2d.drawLine(tmpX_oud, tmpY_oud, tmpX, tmpY);
g2d.drawLine(tmpX, tmpY, tmpX + 8, tmpY - 5);
g2d.drawLine(tmpX, tmpY, tmpX + 8, tmpY + 5);
else{
tmpX = tmpX - (Main.breedte / 2);
g2d.drawLine(tmpX_oud, tmpY_oud, tmpX, tmpY);
g2d.drawLine(tmpX, tmpY, tmpX - 8, tmpY - 5);
g2d.drawLine(tmpX, tmpY, tmpX - 8, tmpY + 5);
g2d.setStroke(normaal);
}**EDIT**
according to this it can be done..
http://java.sun.com/developer/JDCTechTips/2003/tt0520.htm
no clue why mine doesn't work then
Edited by: Nizzle on Sep 13, 2007 10:15 AM -
Need to draw line after the 2nd line item(Smart Forms)
Dear Friends,
I need to draw horizontal line after the 2nd line item and 3rd line item in smart forms.How can i achive this.
Plz help.
Edited by: farook shaik on May 19, 2009 8:19 AMThis is what you need to do:
1> In the tables->details section define two line types LT1 and LT2.
2> Come back to tables section pressing the table painter button.
3> Select a line type for which you want to have an underline(say LT2).
a] If the anchor cursor does not come click the draw lines and columns button( the pencil icon nutton)
b] select the line type ( it will become black after selection. Press and hold down ctrl to select
multiple cells.
c] after selection click the lower 'frame button' ( which is right at the top of box and shading).
4> Now goto data section where you have given your internal table name and work area.
a] in the sort criteria put your field POSNR and check the Event on Sort end chk box.
b] you will see an extra node under the main area of the table.
c] Create a table line with the line type LT2 in the node.
d]Also in the Main area add another table line with LT1 as the line type.
5> If POSNR remains unchnged LT1 will be triggered.
6> if Posnr changes then LT2 will be triggered with the underline.
This will suffice your requirement. -
Here are my last 3 duke dollars. Can someone please help me draw a line?
I have been BEATING my head on this for well over a week now. I'm new to Java2D and I cannot find even one example of this simple little thing that I am trying to do. Not one.
All I want to do is draw an image, zoom that image, then draw some lines on that image, and then zoom it and have those lines show up where they should.
For example, we have an image which has been zoomed. No lines are yet drawn on it.
A line is added.
The image is then zoomed in or out one more time.
How do we get the line to remap to the newly zoomed image?
What I am doing is:
0) Load up an image from a file.
1) Create a zoomed image by using the Image.getScaledInstance() method.
2) Create a BufferedImage with the width and height of the image AFTER the zoom has taken place.
3) Create a Graphics2D object by the createGraphics from this BufferedImage.
4) Place the image into the BufferedImage by doing a BufferedImage.drawImage
5) Select two points to be the start and end of the line.
6) Draw the line using Graphics2D.drawLine(start.x, start.y, end.x, end.y).
7) Zoom the image again (using the Image.getScaledInstance() method.
8) Create a new ImageIcon using the image from above and override its paintIcon method like this:
ImageIcon newIcon = new ImageIcon(newImage) {
public void paintIcon(Component c, Graphics g, int x, int y)
super.paintIcon(c, g, x, y);
zoom(); //<---- ZOOM call
Now in the zoom routine, what do I need to do to get the lines to draw at the proper location and size?
Remember, the points of the lines (stored in a list as home grown line objects) are in screen coordinates, not image coordinates since they are just click points
Note that when I use these points to draw a line, all is well (the line gets drawn where it should), but I have problems when I zoom the image.
Thanks!Below is the documentation and method signature of
Graphics.drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer);The important thing to note is that it does scaling on the fly if the size dictated by the source co-ordinates is defferent than the size dictated by the destination co-ordinates. The source image is always left un-touched.
So basically your visual data is located in an offscreen image. You can draw a line on that. Then create a new image, get it's graphics and call drawImage(original_image, co-ordinates that cause it to scale how you like).
Then you can draw lines on the 2nd image, create a 3rd, ...etc
* Draws as much of the specified area of the specified image as is
* currently available, scaling it on the fly to fit inside the
* specified area of the destination drawable surface. Transparent pixels
* do not affect whatever pixels are already there.
* <p>
* This method returns immediately in all cases, even if the
* image area to be drawn has not yet been scaled, dithered, and converted
* for the current output device.
* If the current output representation is not yet complete then
* <code>drawImage</code> returns <code>false</code>. As more of
* the image becomes available, the process that draws the image notifies
* the specified image observer.
* <p>
* This method always uses the unscaled version of the image
* to render the scaled rectangle and performs the required
* scaling on the fly. It does not use a cached, scaled version
* of the image for this operation. Scaling of the image from source
* to destination is performed such that the first coordinate
* of the source rectangle is mapped to the first coordinate of
* the destination rectangle, and the second source coordinate is
* mapped to the second destination coordinate. The subimage is
* scaled and flipped as needed to preserve those mappings.
* @param img the specified image to be drawn
* @param dx1 the <i>x</i> coordinate of the first corner of the
* destination rectangle.
* @param dy1 the <i>y</i> coordinate of the first corner of the
* destination rectangle.
* @param dx2 the <i>x</i> coordinate of the second corner of the
* destination rectangle.
* @param dy2 the <i>y</i> coordinate of the second corner of the
* destination rectangle.
* @param sx1 the <i>x</i> coordinate of the first corner of the
* source rectangle.
* @param sy1 the <i>y</i> coordinate of the first corner of the
* source rectangle.
* @param sx2 the <i>x</i> coordinate of the second corner of the
* source rectangle.
* @param sy2 the <i>y</i> coordinate of the second corner of the
* source rectangle.
* @param observer object to be notified as more of the image is
* scaled and converted.
* @return <code>true</code> if the current output representation
* is complete; <code>false</code> otherwise.
* @see java.awt.Image
* @see java.awt.image.ImageObserver
* @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
* @since JDK1.1
public abstract boolean drawImage(Image img,
int dx1, int dy1, int dx2, int dy2,
int sx1, int sy1, int sx2, int sy2,
ImageObserver observer); -
How to draw vertical lines that are visible in preview mode?
Hi all,
I need to draw vertical lines on a document. The lines must be same as we draw using line tool.
I could draw the line using CreateLineSpline() method of IPathUtils.
The problem is that these lines are not visible in preview mode. Please tell how can we make lines that are visible in preview mode.
Please help, I'm running out of time.CodeSnippetRunner has the answer:
Utils<IPathUtils>()->CreateLineSpline -
Hi,
in my programm I need to draw straight lines(I hope this is the correct translation for an infinit line). Is there a way of doing this?I just answered my own question.
I checked Illustrator Preferences and under GENERAL: CONSTRAIN ANGLE, mine was set to 0.19 degrees (for reasons unknown).
I changed it to zero and Voila! Who'd have thought this would alter the whole drawing surface?
All I had to do was ask others in order to figure it out myself! Hope this helps anybody else having this bizarre problem.
Vic. -
How to draw centre line with white background?
Hi,
I need to draw a centre line with white background on it. Now i'm doing it by pasting the main line in the background and giving it white so that it shows a white backgound. Is there a way to do just by drawing like normal lines. If we can, is it possible to control the white backgound only to show less than the original line in both ends. This is for illustrations i do for exploding views and i need to draw this line to show it as assembly drawing.
Thanks
Manoj1. Draw a white line segment of desired width (stroke weight) with round cap (Stroke panel) for the background line.
2. Copy, Paste in Front
3. Change to desired foreground color, butt cap, reduce stroke weight.
4. Opt/Alt–drag foreground segment to overhang background segment by desired amount on both ends.
5. Select both segments and drag to Brushes panel, choose Art Brush.
6. In Art Brush Options choose Stretch Between Guides, drag guides somewhere to the inside of curve of round caps. (If in step 3 you chose black, set Colorization Method to Tints. Then you can select any color for the foreground segment by setting the stroke color.) Name the brush as you choose. Click OK.
7. Draw any path and apply the brush. -
Hi! How can i draw a circle over a jFrame?
In general trying to draw directly on a JFrame is not a good idea and can be problematic. You should think about doing your drawing in a JPanel and adding that to the frame
Here are a number of things to look at in drawing a circle
Graphics.drawOval(...)
Ellipse2D, Ellipse2D.Double
Area - you can create an area from any Shape, and it offers a lot of advantages to dealing with Shape
Graphics2D.draw/fill(Shape) -
Drawing a straight line over a video
Is it possible to draw a straight line over a video in CS6 and also to watch the video frame by frame to take exact timings?
Hi Jeff,
Back again! i have managed to put the line over the video and can have it on there as long or as short time as i wish, but it appears to be moving with the video and i need it to stay at a certain point and the video to carry on playing. Basically im trying to mark a point on a race track where the horse in the lead gets to, then i need the line to stay there for when the last horse comes to the line, with the lead horse moving on past. Currently the line doesnt stay on a specific point it on the video and go out of shot when the video moves, it appears to be moving with the video. I know the overlay is a static image but is there a way of making it look like it stays in a specific place on the video?
Hope this makes sense!
Thanks Kat -
The first time I synced my iphone 4 with my mac, I didn't realize that all of my photos from the iphoto library would transfer over to the phone (more than 3,000). Now, I need to remove some, as they are taking up too much space. I cannot figure out how to remove them from the phone. I tried to uncheck boxes and sync again, but I get a message that there is no room on the iphone. I've read as many articles as I can find, but still cannot manage this. Thanks for any help.
Open itunes, connect iphone, select what you want, sync
Maybe you are looking for
-
How do I automatically keep settings unchecked in the 'save as' dialog box?
Hey guys, I use Illustrator CS6. Every day I modify and then save lots of graphics in illustrator. I do a lot of "saving as" with files so that I can see what is selected in the Illustrator options panel. I have to make sure that: -Create pdf compati
-
Ipad2 suddenly can't connect to wifi - password help ?
Hello We've had an ipad2 for about 2 months. We got it connected to WiFi fine by putting in the security key from the Livebox modem and everything was hunkydory. Then we went on holiday for a fortnight and when we got back, there was no way of connec
-
Can anyone advice, from which Database Table I could get 'Cost Center Group Text/Description'. Thanks in advance...
-
JSTL: header / referer in a JSP Document
Hi all, I am about to get the HTTP referer in a JSP Document: <c:forEach items="${headerValues}" var="h"> <c:if test="${h.key == 'referer'}"> <c:set var="logReferer" value="${h.value}"></c:set> </c:if> </c:forEach> However, logRef
-
Issues updating my apps I've had for the past 2 years.