Draw « JPanel « Java Swing Q&A





1. Java JPanel redraw issues    stackoverflow.com

I have a Java swing application with a panel that contains three JComboBoxes that do not draw properly. The combox boxes just show up as the down arrow on the ...

2. Containing drawing to a panel area    stackoverflow.com

I want to draw an array of X and Y integers to a panel in a Java frame. What is the best way to draw the line (currently I'm using Graphic's drawPolyline)? How ...

3. How can I draw rulers in a JPanel?    stackoverflow.com

I have a JPanel that contains an image. I want to draw rulers on the JPanel's borders. How can it be done or where should I look for some hints?

4. JPanel doesnt display the drawing    stackoverflow.com

I have problem displaying drawing on JPanel. I created three class which linked to each other as the following. I was wondering why this code, doesn't display my drawing.

c.add(pDraw);
pDraw.add(draw);
1) MAIN
public class ...

5. Placing drawing on JPanel    stackoverflow.com

My program have 3 classes. 1) main, 2) frame, 3) drawingBoard. The logic of my program is that, a new drawing will be displayed every times user click on New ...

6. java drawing rect in panel    stackoverflow.com

? draw rect on to jpanel but it is only seeing when changing the active operation system window.

7. How to save image drawn on a JPanel?    stackoverflow.com

I have a panel with transparent background which i use to draw an image. now problem here is when i draw anything on panel and save the image as a JPEG ...

8. JPanel component draw order    stackoverflow.com

please see the following code:

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main {
    public static void main(String[] args) {
    final JFrame f=new JFrame("foo");
 ...

9. JPanel redraw problem    stackoverflow.com

I have JFrame, and I added my JPanel class with paintComponent() method. For example I drawed red rectangle, and after some action I want to draw green oval. I tried to ...





10. how to extract information from jpanel    stackoverflow.com

I am trying a project called white board sharing in which I need to get the information from a panel and that information is like some drawings so how can I ...

11. JPanels except the first not drawn    stackoverflow.com

The following code supposed to read a file containing a set of molecular structures, then add a bunch of JPanels (equal to the number of molecules) and create a molecule on ...

12. Should both the toolbar and the draw panel know about each other in this situation?    stackoverflow.com

I have a toolbar with a combobox. When the item changes on the combobox, it makes a call to the draw panel (which the toolbar has a reference to) to tell ...

13. trying to attach a frame to a panel and draw a polygon , but there is no drawin on the frame    stackoverflow.com

I'm developing a simple gui using javax.swing and tried to draw some polygons usings command buttons 3 to 9 say if you press command button number 3 it should draw a ...

14. JPanel drawing issues    bytes.com

15. draw on jpanel doesnt work    forums.netbeans.org

im really new to gui programming, i excuse in advance for such a basic question... i just want do draw something on a jpanel... this piece of code is just to figure out how the several tutorials work. but when i try to execute the app nothing happens...

16. drawing on a JPanel without erasing the underlying drawings    coderanch.com

Hi I am using a JPanel (with double buffering on) to draw lots of shapes like lines, circles etc. When the user draws another shape, it is drawn over the existing shapes and a repaint for all shapes has to be called. Is it possible that the temporary/intermediate shapes being drawn on the shape do not overwrite / erase the underlying ...





17. Draw something on JPanel    coderanch.com

It takes me much time to make clear how to draw something on a panel. Firstly I used the methods of Graphics drawing on panel directly, but as all know, it can not be reserved if the window changed. Then, I used BufferImage with the instruction from JavaRanch. It works well, and I finished my assignment at last. However, are there ...

18. Need help with drawing in a JPanel    coderanch.com

Hi, I am trying to draw a graph in a JPanel but am not sure exactly how to achieve this. I have created GUI application and want to add graph as one JPanel in main JPanel there. Here is the code I have written which works fine standalone. import java.awt.Graphics2D; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class BarGraph extends JPanel ...

19. HOW to draw an ARC on a Frame / Panel    coderanch.com

You mention Frame and Panel which are AWT components so I assume you want to work in the AWT visavis Swing. Some suggestions: 1 create a class that extends either Canvas or Panel and override its paint method to do your drawing class PiePanel extends Panel { ... public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D)g; // draw ...

20. Drawing not displayed on JPanel    coderanch.com

I am trying to draw a binary tree on a JPanel. I subclassed JPanel and overrided the paintComponent method. However, my nodes aren't being drawn. When the application starts, there is no tree to display and text is displayed in the window asking to load a new tree. This part is working. But when I load a tree, I just get ...

21. drawing in a JPanel?    coderanch.com

22. How to store what the JPanel draw    coderanch.com

Welcome to the Ranch. You obviously missed the naming policy when you logged in: first name-space-last name. Please correct your displayed name to match. No, we can't show you an example of what would work; you aren't going to learn anything from that. Rather, you show us what you have got and tell us what you think is going wrong. Please ...

24. Drawing in JPanel    coderanch.com

Hello, I must start by saying that I'm not entirely sure if this is the right section to post this question. With that taken care of, now for my question. I am trying to set up a Java Desktop Application using net beans. It requires that I do some drawing; hence, fromsurfing the web, is discovered that most people draw on ...

25. Drawing Problems with JPanel /Jframe need optimize solution.    coderanch.com

Dear Experts, I m trying to create a GUI for puzzle game following some kind of "game GUI template", but i have problems in that ,so i tried to implement that in various ways after looking on internet and discussions about drawing gui in swing, but i have problem with both of these, may be i m doing some silly mistake, ...

26. Drawing on a JPanel fails    coderanch.com

I am drawing strings on a JPanel after I draw the image of a JPG. The paint component method is protected void paintComponent(Graphics graphics) { super.paintComponent(graphics); if (this.bufferedImage == null) return; // if (this.firstTime) { int width = getWidth(); int height = getHeight(); Image scaledImage = this.bufferedImage.getScaledInstance(width, height, BufferedImage.SCALE_DEFAULT); Insets insets = getInsets(); graphics.drawImage(scaledImage, insets.left, insets.top, null); this.firstTime = false; // ...

27. Problem: Slow drawing on a jpanel    coderanch.com

Hi everyone! I am working on a free draw project but I've been stuck. I am trying to create a XPanelGraphics (extended JPanel) in which I can draw. The user can either draw or erase what he/she has drawn. I use jLayeredPanel with two layers, xPanelGraphics both. Here is the code of the XPanelGraphics public class XPanelGraphics extends JPanel implements MouseMotionListener, ...

28. Looking for help on drawing stuff in a jPanel    java-forums.org

Hello All - I wasn't sure where to post this, but this seems like the appropriate forum. So I'm using the NetBeans IDE and it's GUI application. I Drag and drop a panel into the frame and I want to draw something into it. So I looked on google and all the tutorials I find explain it in a code perspective ...

29. drawing in JPanel ,beyond the co-ordinates    java-forums.org

hey guys,i have been trying to make a binary tree GUI representation,I am facing a problem in the following code class GuiPanel extends JPanel{ int x=200,y=10; Tree current_node=root; void print3(Tree present,int x,int y,Graphics g){ int temp=present.GetKey(); String tempp=Integer.toString(temp); g.drawString(tempp,x,y); if(present.GetHas_Left()){ print3(present.GetLeft(),x-50,y+50,g); g.drawLine(x, y, x-50, y+50); } if(present.GetHas_Right()){ print3(present.GetRight(),x+50,y+50,g); g.drawLine(x, y, x+50, y+50); } } after a few entries,the x-50 term goes ...

30. Drawing image on JPanel from another frame    java-forums.org

class RSlika extends JPanel { private Image img; private int x, y; public RSlika(Image img, int x, int y) { this.img = img; this.x = x; this.y = y; } public void paintComponent(Graphics g) { super.paintComponent(g); Dimension d = getSize(); Insets i = getInsets(); g.drawImage(img, i.left + 2, i.top + 2, d.width - i.left - i.right - 4, d.height - i.top ...

31. Drawing on Jpanel    java-forums.org

32. How to display the black Polygon that I draw on the panel?    java-forums.org

Hi guys I have 2 problems here: 1. Below code does not show a black Polygon that I draw on the panel, only shows an empty Frame named "Poppy" 2. Once the frame shows, I can't close it by clicking "x" at the right top corner. Does anyone know why? Thanks heaps Java Code: package brainydraw; import java.awt.*; import java.awt.event.*; import ...

33. Draw on JPanel, Help    java-forums.org

protected void paintComponent(Graphics g) { System.out.println("in paintstuff"); super.paintComponent(g); if(text) { System.out.println("Here"); Graphics2D g2 = (Graphics2D)image.getGraphics(); g2.drawString(textString, lastX, lastY); text = false; } if (image == null) return; switch (style) { case TILED: drawTiled(g); break; case SCALED: Dimension d = getSize(); g.drawImage(image, 0, 0, d.width, d.height, null); break; case ACTUAL: drawActual(g); break; } }

34. Drawing Graph and Add to JPanel    java-forums.org

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package DrawPanel; import java.awt.Color; import java.awt.Graphics; import javax.swing.JPanel; import javax.swing.JFrame; /** * * @author NguyenDuyLong */ public class Draw extends JPanel{ public double x1,x2; public int xCenter; public int yCenter; public Draw(){ super(); setVisible(true); setBackground(Color.blue); setForeground(Color.red); } @Override public void paintComponent(Graphics g) ...

35. How to draw in a JPanel using Netbeans 6.1 GUI maker    java-forums.org

Hello Everyone - So I'm pretty new to the java language, but I've been coding in C/C++ and C# for awhile now. I know C# is basically a rip-off clone of java so it hasn't been to difficult to pick things up. The problem I am having is drawing 2D objects in a JPanel. I've read the differnt tutorials online about ...

36. Drawing with JPanel    java-forums.org

import java.awt.*; import javax.swing.*; public class GraphTest { public static void main(String[] args) { JFrame frame = new JFrame("Test app"); JPanel panel = new JPanel(); initFrame(frame, panel); } private static void initPanel(JPanel p) { p.setBackground(Color.white); p.setFocusable(true); p.setPreferredSize(new Dimension(500,500)); } private static void drawSomething(JPanel p) { Graphics g = p.getGraphics(); if(g == null) { System.out.println("Can't get graphics"); return; } g.setColor(Color.black); g.fillRect(200,200,50,100); p.repaint(); ...

37. Drawing an image on JPanel    java-forums.org

Hello! I have made applet using Swing, which has one JPanel and one DesktopPane with labels and sliders. I want to draw shapes and images on JPanel, but I don't know how to do it. I tried to draw image, but I lose all my panels and got just picture. I think that main problem is that I don't know how ...

38. Draw on JPanel?    java-forums.org

39. Simple drawing on a JPanel    java-forums.org

Hi I am having problems drawing onto a JPanel. All I need basically is to be able to draw a 9x9 grid onto a jpanel. My problem is I can't even get it to draw one line. I need to make this as an application so here is the basic code I'm trying to use Java Code: import java.awt.Graphics; import java.awt.*; ...

40. How To Draw Objects Not On A JPanel    java-forums.org

Why would you want to draw directly on the JFrame and not on the JPanel? If we knew your rationale for going against standard practice, perhaps we could help you better. Which part of the JFrame do you plan on drawing on? The content pane? root pane? glass pane? layered pane? Do you know the reasons why the google search is ...

41. how the netbean gui orgnize the jpanels? draw something in a frame?    forums.oracle.com

Whenever you add something to a contentPane, understand that its placement is being managed by the BorderLayout layout manager. By adding the component without specifying where you want it, it by default is added BorderLayout.CENTER which means that it covers the entire JFrame. I'm guessing that you want to add this panel BorderLayout.SOUTH or perhaps with another layout manager. Suggestion: Ditch ...

42. jPanel drawing problems    forums.oracle.com

public void paint(Graphics g) { super.paint(g); g=envjPanel.getGraphics(); g.drawString("Ciao mondo",100,100); } where envjPanel is my jPanel object. The paint method above is defined and called inside the class extending jFrame. I also tryied by overriding paintComponent method as suggested in "Painting in AWT and Swing" article but the drawed string isn't persistent. I ask you if there is a cleaner way to ...

43. Drawing on JFrame / JPanel in Netbeans    forums.oracle.com

Hello All, I'm writing a project in NetBeans 5.5, and I need to draw some graphics onto my form, or even more preferable my panels. I've drawn on stuff before in java using the .drawRect etc. method, and although this is fairly simply, I'm now using NetBeans and can't figure out how to do it! I realize that these forums are ...

44. drawing on a jpanel    forums.oracle.com

45. Help to Draw on a Jpanel    forums.oracle.com

I read the tutorials, but it doesn't say anything about painting on Jpanels, i know i cant make a jpanel in the graphics part but i am just trying to do something like this. [http://forums.sun.com/thread.jspa?threadID=452259&forumID=31] So, what i'm trying to do is to draw the stuff on a Jpanel which is in the center of my frame, but it always starts ...

46. Can we draw simultaneously on a JPanel?    forums.oracle.com

I have to develop a whiteboard application in which both the local user and the remote user should be able to draw simultaneously, is this possible? If possible then any logic? I have already developed a code but in which i am not able to do this, when the remote user starts drawing the shape which i am drawing is being ...

47. Drawing multiple object on JPanel    forums.oracle.com

48. Problem with Drawing on jPanel    forums.oracle.com

I didn't look too closely at the code, but I thought the OP was using mouse events to accumulate data. In this case, you can maintain a BufferedImage that you add the latest mouse droppings to, then simple blit in in paintComponent. This is a different strategy for buffereding than Swing's, which is just to avoid repaint-flashing.

49. drawing to JPanel    forums.oracle.com

Swing related questions should be posted in the Swing forum. I have never had much luck using the getGraphics() method, I always use the passed Graphics object instead. When I did some testing on this I determined that the Graphics object is different in the two cases. So the only reliable Graphics object to use the the one that is passed ...

50. can i draw table on jPanel?    forums.oracle.com

i'm making the time schedule for my university department. and i have a trouble i'm making the engine it's works already. but now my teacher told me that i'll make a GUI i can't use jTable it's not flexible. my time table is complex , in one period may have many sections , section period is not a same long. bla ...

51. Drawing on JPanel    forums.oracle.com

g2.setColor(Color.black); //draw lines betwen circles for(int i=1;i