Graphics « Graphics « Java Swing Q&A





1. How to combine repaints in Swing?    stackoverflow.com

I am calling repaint a bunch of times from a listeners, but the way I designed my paint function is only one repaint is required. I generate a bunch of ...

2. Which is the best GUI tool for J2ME apps    stackoverflow.com

I m doing a commercial j2me project in which I need some good Gui like tabbed pane and auto complete text boxes and I need a constant look and feel across ...

3. A graphics code generation tool development    stackoverflow.com

I am trying to build a tool for our embedded system project. Our embedded system controls a giant machine performing several safety critical activities. For time being lets imagine it to ...

4. Cannot Understand The Exception    stackoverflow.com

This is the code :

import java.awt.*;
import javax.swing.*;

class tester {
JFrame fr;
JPanel p;
Graphics g;

tester() {
 buildGUI();
}

public void buildGUI() {
 fr=new JFrame();
 p=new JPanel();
 p.setBackground(Color.red);
 g.setColor(Color.black);
 g.drawOval(18,45,78,39);
 g.fillOval(18,45,78,39);
 fr.add(p);
 fr.setVisible(true);
 fr.setSize(500,500);
}

 public static void ...

5. Remote GraphicsEnvironment Java Swing    stackoverflow.com

The API from Java seems to indicate that it is possible to have a GraphicsEnvironment that is running in a separate machine:

The resources in this GraphicsEnvironment might be local ...

6. Java Beginner Question simple Graphics    stackoverflow.com

I'm getting an error saying that the methods are not applicable for the type Graphics? I don't fully understand whats going on here - could anyone explain what I'm doing wrong ...

7. Comparison of Processing vs JavaFx vs Griffon    stackoverflow.com

Can anybody compare Processing vs plain JavaFX vs Griffon with Swing/Fx builders? I am interested in the sweet spots of each tooklkit, and in particular for building rich visualization dashboards.

8. Game Programming in Java    stackoverflow.com

I know this is a somewhat common subject, but the information is outdated quickly. I want to stay with the times on the topic... Anyway, I am looking into creating a 2D ...

9. How can instance link to Graphics element can be passed to further manipulations in java swing?    stackoverflow.com

How to create custom shape on JPanel and then pass link to external(outside a class) function its link to manipulate (to call a private function to change position etc.)? Example:

import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import ...





10. Bug in Sun's Java SE 1.3 Graphics.setFont?    coderanch.com

Everything works fine in the appletviewer. I compile an applet under JavaSE 1.3 that uses Graphics.setFont and under 1. Netscape 4.75 it seems to have no effect. 2. IE 5.5 it hangs the applet So I then use J++ V6 and it works. Is this a bug in Sun's Java Standard Edition 1.3? Can you make this source code work with ...

11. problems using paint(Graphics g)    coderanch.com

12. Graphics    coderanch.com

13. Graphics Grumbling    coderanch.com

Simcel, I think I may have at least a little here to get you going in the right direction. For starters, the .getGraphics() call is to be used on Components. JPanel extends from JComponent and not component so that isn't fetching up the graphics for you like you want. Now, I've reworked your code with a couple slight modifications, take a ...

14. graphics with swing    coderanch.com

15. Graphics    coderanch.com

16. Help on Graphics and repainting.    coderanch.com





17. Scale a page using Graphics    coderanch.com

No i do not mean limiting the area printed but to reduce the size of the fonts proportionately so that the whole web page is acomodated in one page. ofcourse by that i mean width wise well accomodated and not page wise. if the matter spans over multi pages then it will continue doing so. this i am able to do ...

18. saving graphics    coderanch.com

I just a beginer but I had an Idea.... thanks to this lovely forum I've learnd how to do animation by useing a buch of gif file and loading them into a Graphics object but and then playing them. but that means a lot of gif files so my idea was, can one not create a graphics array and load all ...

19. Swing graphics    coderanch.com

Can anyone direct me or tell me where to get starting on dragging an image with the mouse in Swing. I have looked at the 2D API and was wondering if there is another method for doing so. The 2D examples all move painted rectangles and not Images such as GIFS or JPEGS. Any suggestions??

20. graphics in JBuilder    coderanch.com

You can create instances of any swing component u like and add it to the panel, and then draw some grpahics onto the panel as well. However the fact that you want to do this suggests that you may want two panels, one for drawing, one for components, but it depends on how yu want th egui of your app. Just ...

21. Graphics and Swing    coderanch.com

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class LinePanel extends JFrame { public LinePanel() { super( "Line Panel" ); Container contents = getContentPane(); JPanel p = new JPanel(); p.setLayout( new GridLayout( 5, 1 ) ); p.add( new JLabel( "TOP" ) ); p.add( new JSeparator() ); p.add( new JLabel( "BOTTOM" ) ); p.add( new JSeparator() ); p.add( new JLabel( "Which side are ...

22. Graphics    coderanch.com

If you have a Graphics object that has had text added to it by using the drawString(String, int, int) method, how can I get to this text at a later time? I am in a situation where I see a JPanel and I can do a getGraphics() on it, giving me a Graphics object. I don't have acces to the java ...

23. awt graphics    coderanch.com

24. Saving Graphics    coderanch.com

25. Wierd graphics problem....    coderanch.com

I am using the java swing components and i am have graphics redrawing problems. I have tried pretty much everything but I can't seem to correct it. It only does it on windows machines, not on macintoshes. I have a method that draws a bunch of lines on the screen , when the window is moved or reshaped the lines are ...

26. Graphics.translate(x,y) ?    coderanch.com

Maybe one of you can answer this. The docs for translate() state: Translates the origin of the graphics context to the point (x, y) in the current coordinate system. Modifies this graphics context so that its new origin corresponds to the point (x, y) in this graphics context's original coordinate system. All coordinates used in subsequent rendering operations on this graphics ...

27. JFC--- Graphics    coderanch.com

Hi, do you want to use a ready Component like JTree, where you fill all your data in a model or do you want to draw it by your own. Both is possible. Maybe using JTree would be better in your case. The tree itself can have only one root, but if you need more, then you can hide the root, ...

28. Graphics problems    coderanch.com

Hello People, I'm trying to write a game that invloves placing a piece on a "board" and then doing stuff to it, like moving it about etc.. I would like to have a grahic that is independent of the board, but I don't know how to do this. At the moment, I have a piece that I place on the board, ...

29. paint won't call graphics    coderanch.com

30. Abrstract Graphics    coderanch.com

Mine says sun.java2d.SunGraphics2D... I would guess this is either a different class for every platform, or that this same class calls different native libraries based on the platform... The point is that you shouldn't care what class actually does this, as long as you can call the abstract Graphics methods you can draw on the components. Here's the class I used ...

31. basic graphics (user interfaces) HELP!    coderanch.com

The window is empty because after you assemble the set of nested JPanels, you don't use them -- i.e., you never add() them to the JFrame itself; i.e., you need to call getContentPane().add(theBox) as the last line of the optionsFrame constructor. Let me give you a couple other tips while I'm here, if you don't mind. First, there's a very strongly ...

32. Some Graphics Questions    coderanch.com

I'm drawing 6 polygons on a frame 2 rows by 3 cols. I need to know how to Q1) Rotate the polygon Q2) Scale the polygon Q3) label the vertices of the polygon Q4) "pack" the 6 polygons relative to the window size so that they do not overlapped or remain unseen since the coordinates will be values input by the ...

33. Graphics roaming around desktop    coderanch.com

Anybody remember the little pet applications where a dog or cat is wandering around the desktop and interacting with your mouse pointer? Is there a way to do something like this in Java? Whether on the desktop or within a browser window but on top of your web page... If so, would this be done by making the frame transparent and ...

34. Graphics    coderanch.com

I'm pretty much a Java "newbie", and need some help with my GUI. I have a graphic ('logo.bmp' at 66x70pixels) and I want to use it as my logo for the GUI, how do I go about this? Please keep in mind I'm not using HTML to access the *.java file, I'm using JCreator. Thanks in advance, Adam.

35. Doing graphics in Java    coderanch.com

To put on a water mark, you'll need first a file loader for the pictures, then when you have the pixel information stored in an RGB array, you just want to subtract a fraction of the watermark's RGB values to the main picture's RGB values, pixel by pixel. If you want to emboss an image by putting a little shadow around ...

36. graphics problem    coderanch.com

import java.awt.*; import java.awt.event.*; import java.awt.font.*; import javax.swing.*; public class TextTest { public static void main(String[] args) { TextPanel textPanel = new TextPanel(); TextUIPanel uiPanel = new TextUIPanel(textPanel); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(uiPanel, "North"); f.getContentPane().add(textPanel); f.setSize(400,250); f.setLocation(200,200); f.setVisible(true); } } class TextPanel extends JPanel { Font font; String text; public TextPanel() { font = new Font("lucida bright regular", Font.PLAIN, ...

37. Serialization and Graphics    coderanch.com

because a graphics context is usually quite unique to a machine/address space/device and serialising it over the wire makes absolutely no sense to the receiving context. Basically, wanting to draw onto a remote graphics context is a very very bad idea. If you are wanting to say remotely control/cause to draw things between some client and server then you are better ...

38. bench for graphics    coderanch.com

39. Why Graphics.drawRoundRect() not have symmetrical corners?    coderanch.com

Without seeing exactly waht is going on, and not having your code in front of me, is there some other component that may somehow be interfering? I can't think of anything else right off hand, and I guess I can't think of ever having run into that particular problem before. I have had weird things happen with graphics when I tried ...

40. Getting errors while trying to get graphics environment    coderanch.com

Its a webapp. An error occured during PDF generation on linux machine. Below is the stack trace. java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable. sun.awt.X11GraphicsEnvironment.initDisplay(Native Method) sun.awt.X11GraphicsEnvironment.(X11GraphicsEnvironment.java:134) java.lang.Class.forName0(Native Method) java.lang.Class.forName(Class.java:141) java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62) net.sf.jasperreports.engine.util.JRGraphEnvInitializer.initializeGraphEnv(JRGraphEnvInitializer.java:102) net.sf.jasperreports.engine.fill.JRBaseFiller.(JRBaseFiller.java:213) net.sf.jasperreports.engine.fill.JRHorizontalFiller.(JRHorizontalFiller.java:130) net.sf.jasperreports.engine.fill.JRHorizontalFiller.(JRHorizontalFiller.java:122) net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:146) net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:353) net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:274) net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:242) com.util.ReportUtil.makeReport(Unknown Source) com.admin.handler.PersonnelMgmtCmd.showPersonnelReport(Unknown Source) com.admin.handler.PersonnelMgmtCmd.execute(Unknown Source) com.servlet.BtmAdminServlet.processRequestType(Unknown Source) com.servlet.BtmAdminServlet.doPost(Unknown Source) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) javax.servlet.http.HttpServlet.service(HttpServlet.java:810) Some ...

41. J2SE 1.5.0 Graphics.fillPolygon method    coderanch.com

Hi Java Folks, Sorry to bother everyone, however, I am all out of ideas on a particular problem that I am having, and am hoping that someone can offer some advice. In short, my Java problem is as follows: [1] over the past year I have *successfully* implemented a "graphical geometry editor" using J2SE SDK 1.4.x. Again, everything worked fine under ...

42. Graphics Problem    coderanch.com

Hi all I am developing a solution to a small problem . The problem is , i have to proof the (a+b)^3 using geometrical representation. Since (a+b)^3 is a cuboid. i searched for java api for created cuboid. But i did not find . what i did i created a cuboid using a combination of graphics drawLine() and drawRect() method. But ...

44. graphics    coderanch.com

45. combining controls and graphics    coderanch.com

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.applet.*; // public class testing extends JApplet implements Runnable //, WindowListener { Thread t; int i, j, x, y; public volatile boolean run=true; JButton b1, b2; /*public static void main(String args[]) { testing tst=new testing(); }*/ public void init() { b1=new JButton("stop"); b2=new JButton("start"); JPanel p=new JPanel(); //setBackground(Color.pink); p.add(b1); p.add(b2); //pack(); ...

46. Improving Graphics    coderanch.com

Hi, So far i heave created the following code which create a kind of spinning wheel. At the moment the images jump down 50 pixels at a time which looks jerkey not smooth. Im looking for either some help here or links to other sites where I can find tutorials on this. The main goal is to create a fruit machine ...

47. Using graphics    coderanch.com

I am trying to develop a gui using swings and graphics. I have a Frame with two Panels. One Panel is used for the graphics part and the other to have a textfield and a button. When i try to draw a line on the graphics panel, i should get the coordinates on the text filed. Everything works fine, but when ...

48. graphics corruption    coderanch.com

hello! thanks for your suggestion, but the problem in my case is not related to the graphics acceleration! i've disabled my mouse driver and confirmed my suspecions. indeed it seems that my synpatics touch pad (version 7.xx) seems to have been the culprit. after reinstalling an ealier version the problems seems to be gone away. thanks, tian.

49. graphics    coderanch.com

50. Advanced Swing/Graphics java book    coderanch.com

51. Clickable Graphics    coderanch.com

I am making a simple memory game with a GUI. I am progressing along, but I am not sure how to handle the cards on the screen. Should I use graphics objects and add mouse listeners to detect which ones I have clicked so I can display a picture file icon or is there a more efficient way that bundles what ...

52. Vector graphics    coderanch.com

53. Graphics and JVMs    coderanch.com

I have written this small test code to show the difference in the graphical output of 2 different JVMs i.e. Apple JDK 1.5.0 and Windows JDK 1.5.0_13. When I execute this code in Apple JVM, I can see the message "Hi There" quite clearly. Whereas, in Windows JVM, the message is harder be seen if I set Thread.sleep to 100. If ...

54. why wont this graphics respond?    coderanch.com

when I call repaint all that happens is that page is set back to green class Paper extends JPanel { public void paintComponent(Graphics g) { G = g; g.setColor(Color.GREEN); g.fillRect(0, 0, 350, 350); checkDead(); //this makes sure we are drawing rabbits that are still there for(Rabbit r : rabbits) { if(r.getPoint() == null) { r.draw(false, points, page, g);//draw does some random ...

55. Graphics and Swing??    coderanch.com

I'm not quite sure what your 'rows' are. Are they just goemetry/test that you have draw using a graphics context? If so, you will need to define how you associate things together in a row, maybe just by where they are on the component on which you have drawn them. You also need to decide how to highlight a row, maybe ...

56. Prudence of AWT and Graphics/GUI design    coderanch.com

In my review of Java (and urgency to expidite to get certified) I have a quick question. This book I'm using (Deitel 4th) had chapters on 2D Graphics and GUI design (2 about the whole Swing library it seems). My thinking is that if I am using this book to review for the exam before I sit down and take mock ...

57. Problem with graphics    coderanch.com

I'm making a game. This game uses a single timer, which executes a "step" event in all of the game's objects, then calls repaint, which calls repaint in all of the game's objects. The objects do not have their own container, they all draw themselves directly to the JFrame's graphics object. The problem is that the graphics tend to glitch. Horizontal ...

58. Swing graphics problems    coderanch.com

Hi guys, I'm new to Java programming (and GUIs) and I can't figure out why my program is doing this. This is a very simple program that Starts out with a square rectangle at the top left of the screen, and when the user clicks on the screen it should redraw a new rectangle at the point where the screen is ...

59. graphics beginner    coderanch.com

60. graphics.copyArea()..why would I use an iteration?    coderanch.com

[b]before...[/b] ImageComponent.java public void paintComponent(Graphics g) { if (image==null) return; int imageWidth = image.getWidth(this); int imageHeight = image.getHeight(this); //draw the image in the top-left corner g.drawImage(image, 0,0,null); //tile the image across the component for (int i = 0; i * imageWidth <= getWidth(); i++) { for (int j = 0; j * imageHeight <= getHeight(); j++) { if (i + j ...

61. Help wiht basic Graphics    coderanch.com

Hi everyone, I've not done any programming in a while and am tinkering with some graphics to keep my little grey cells working. I'm stuck on a couple of things though, so any help on this would be appreciated. import java.lang.*; import javax.swing.*; import java.awt.*; import java.awt.image.*; import java.awt.geom.*; public class Test { public static void main(String[] args) throws Exception { ...

62. Need help on Graphics and repaint    coderanch.com

Hi I don`t know if this is the right place to post my topic but I really need help from you. I have two questions that I can`t find any answers to them. In java.awt package there is an graphics class this class is abstract class and within it a lot of abstract methods for example lets take drawOval method all ...

63. Graphics in java    coderanch.com

64. Graphics problem , how to approach ?    coderanch.com

65. Can't get Graphics.setFont() to work    coderanch.com

Hi and thanks for your incredibly quick replies! The guess that createGraphics() threw away all the previous settings, proofed to be right. I have modified the code, it works now flawlessly. I however wonder, if my solution is good style, as the thing with 'Graphics g = image.createGraphics();' looks somewhat strange to me!? I thought that I could replace 'image' with ...

66. Help with project using graphics    coderanch.com

Hi Everyone, I am working on a school project (I am sure it is a first) and I am running into some problems. I have to build three classes; two classes to generate the items and a ArrayList, and the last one is a test class. I started working on the first class that is suppose to create a Car and ...

67. If swing is betters graphics handler than awt, why do we need to use awt at all?    coderanch.com

Thanks. I was asking cause I just wanted to learn about one package instead of both. So you guys say that I have to use awt classes while designing an interface with swing. But there are so many damn classes, how do I know off hand which package the classes are in, and what classes I would need to say put ...

68. Swing graphics problem    coderanch.com

import javax.swing.*; import java.awt.event.*; public class SimpleGui1B implements ActionListener { JButton button; public static void main (String args[]) { SimpleGui1B gui = new SimpleGui1B(); gui.go(); } public void go () { JFrame frame = new JFrame(); button = new JButton ("click me"); button.addActionListener(this); frame.getContentPane().add(button); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300,300); frame.setVisible(true); } public void actionPerformed(ActionEvent event) { button.setText("I've been clicked"); } } class MyDrawPanel extends ...

69. Java Software Solutions Graphics Example 3.9 noob help    coderanch.com

Hey guys This is my first post, and hope this board is alot more helpful towards new programers then the last one I joined. Apparently something about programing makes people a little rude lol. Anyway Im working on a graphics example listed above and I understand it, but when I run the code the icon gif of the devil doesent show ...

70. Graphics in NetBeans IDE    coderanch.com

So it's been recommended to me that I use NetBeans IDE for ease of use in GUI-Swing stuff, and thus I have been working on figuring it out. It is not intuitive for me, at least, but I'm willing to give it a shot. Does anyone here know how to draw graphics primitives on bean/module containers or other swing elements? Am ...

71. Way to group graphics together?    java-forums.org

Is there a way to group graphics into one graphic? I have a rectangle with a string inside, and I want to use it for a drag and drop function, but right now it is only moving the rectangle, and the string stays put. Also, can i make the string editable? I want the use to be able to click on ...

73. swing mixed with awt graphics    java-forums.org

HI all, First i am limited in placing code Ill do my best to explain what is missing. Thanks I am mixing the graphic interface similar to Goole maps, currently I am working on a pan zoom feature that zooms in on multiple map images. I do not know what the graphics are at this time I have been using gif ...

74. java graphics question    java-forums.org

Java Code: import java.awt.Color; import java.awt.event.KeyListener; import java.awt.event.KeyEvent; import java.awt.Graphics; import javax.swing.JPanel; import javax.swing.JFrame; import java.awt.Dimension; public class Tanks extends JPanel { private static int x = 150, y = 150; private static int c_x = 0, c_y = 0; private static boolean cannon = false; public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.BLACK); g.fillRect(x, y, 50, 50); if(cannon) { g.setColor(Color.RED); g.fillRect(c_x, ...

75. Using methods for graphics    java-forums.org

I apologise if this is wrong/obvious/the wrong place to put this/stupid but I could really do with some help. I started studying programming and we've been told to make a map of a region and use various techniques. I'm trying to make 3 'bars' which are essentially just circles, and I've been told to create them using methods. I don't understand ...

76. calling Graphics functions within for loop yields strange results    java-forums.org

I have a program that works fine (paints graphics where I expect and graphics don't disappear on window resize/minimize) if I call Graphics functions individually, However if I make the same calls within a for loop, the graphics are shifted and also disappear on window re-size or minimize. Specifically, I have an array (grades[]), and making the following calls within my ...