public class ImageDisplay extends JPanel implements MouseListener { private Dimension area; //indicates area taken up by graphics private Vector<Rectangle> circles; private JPanel drawingPane;
private final Color colors[] = { Color.red, Color.blue, Color.green, Color.orange, Color.cyan, Color.magenta, Color.darkGray, Color.yellow}; private final int color_n = colors.length;
public ImageDisplay() { super(new BorderLayout()); area = new Dimension(0,0); circles = new Vector<Rectangle>();
//Set up the instructions. JLabel jlableLeft = new JLabel("Click left mouse button to place a circle."); JLabel jlableRight = new JLabel("Click right mouse button to clear drawing area."); JPanel jpane = new JPanel(new GridLayout(0,1)); jpane.setFocusable(true); jpane.add(jlableLeft); jpane.add(jlableRight);
//Set up the drawing area. drawingPane = new DrawingPane(); drawingPane.setBackground(Color.white); drawingPane.addMouseListener(this);
//Put the drawing area in a scroll pane. JScrollPane scroller = new JScrollPane(drawingPane); scroller.setPreferredSize(new Dimension(200,200));
//Lay out this demo. add(jpane, BorderLayout.PAGE_START); add(scroller, BorderLayout.CENTER); }
/** The component inside the scroll pane. */ public class DrawingPane extends JPanel { protected void paintComponent(Graphics g) { super.paintComponent(g);
Rectangle rect; for (int i = 0; i < circles.size(); i++) { System.out.println("circle size: " + circles.size()); rect = circles.elementAt(i); g.setColor(colors[(i % color_n)]); g.fillOval(rect.x, rect.y, rect.width, rect.height); } } }
August 26, 2008 at 7:37 PM
//Handle mouse events. public void mouseReleased(MouseEvent e) { final int W = 100; final int H = 100; boolean changed = false; if (SwingUtilities.isRightMouseButton(e)) { //This will clear the graphic objects. circles.removeAllElements(); area.width=0; area.height=0; changed = true; } else { int x = e.getX() - W/2; int y = e.getY() - H/2; if (x < 0) x = 0; if (y < 0) y = 0; Rectangle rect = new Rectangle(x, y, W, H); circles.addElement(rect); drawingPane.scrollRectToVisible(rect);
int this_width = (x + W + 2); if (this_width > area.width) { area.width = this_width; changed=true; }
int this_height = (y + H + 2); if (this_height > area.height) { area.height = this_height; changed=true; } } if (changed) { drawingPane.setPreferredSize(area); //Let the scroll pane know to update itself //and its scrollbars. drawingPane.revalidate(); } drawingPane.repaint(); } public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mousePressed(MouseEvent e){}
private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("Scroll example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane. JComponent newContentPane = new ImageDisplay(); newContentPane.setOpaque(true); //content panes must be opaque frame.setContentPane(newContentPane);
//Display the window. frame.setSize(300,300); frame.setVisible(true); }
public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } } ------------------------------
Thanks
Amardeep
Related Pages:
Scroll in JPanel Scroll in JPanel Hello sir, Hi Friend,
You can use the following code:
import java.awt.*;
import javax.swing.*;
class scroll
{
public static void main(String[] args)
{
Frame f = new Frame ("Demo");
JPanel p = new
Press button and Scroll Image to Scrollpanel
Press button and ScrollImage to Scrollpanel Insert image into the jpanel,inside the jscrollpane.If i press the button and scrollimage
displaying image displaying image how to upload image and retrieve it form database mysql in php?
Here is an example of uploading imageusing php.
1)form.html:
<form method="post" enctype="multipart/form-data" action="upload.php
displaying image in awt - Java Beginners displayingimage in awt Hi All,
I have downloaded the code to display imageusing awt from here and when I execute the code I am getting... ActionListener{
JFrame fr = new JFrame ("Image loading program Using awt");
Label
Displaying error on the Same form Displaying error on the Same form I want to display the errors on the same form(Top of the form) after validation. I am used Div element and Table.... There is a root Div element they are using for Window purpose. I tried to resize it using DOM
Displaying image using jsp and spring. Displayingimageusing jsp and spring. how to display an image stored in WEB-INF/images folder on the browser using jsp and spring
image displaying in java imagedisplaying in java how to display an image by using load image button in applet viewer
how to scroll multiple images using on Click in Android
how to scroll multiple images using on Click in Android I am new... there is requirement like multiple image scrolling dynamically. But unfortunately i am unable to scroll multiple images. But i am able to scroll single image.
plz let me know
problen in displaying the text and image in gallery using Android
problen in displaying the text and image in gallery using Android public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gallery = (Gallery
Displaying search results in same panel of gridview in same jframe window. Displaying search results in same panel of gridview in same jframe window... search and see the results in the same panel of the Jframe in Gridview Jtable... should be displayed in the jpanel of jframe window....
import java.sql.*;
import
Displaying search results in same panel of gridview in same jframe window. Displaying search results in same panel of gridview in same jframe window... search and see the results in the same panel of the Jframe in Gridview Jtable... should be displayed in the jpanel of jframe window....
import java.sql.*;
import
Jpanel allignment Jpanel allignment i have two panels added one below anotehr. and i have a one button.
when i clicked button. the first panel ara should... using gribaglayout or any layout.
need quick reply.
thanks in advance
Displaying image with byte array[] - Java Beginners Displayingimage with byte array[] Hi Frndz..
As per my requirement i need to show an image by using an byte array object which have image data in binary format.
The challenge here i have only byte array[] object ,by using
How to save JPanel as gif or jpeg file
How to save JPanel as gif or jpeg file i draw polygons , rectangles, lines on jpanelusing draw line method drawpolygon methods etc, now i want save the data of jpanel which is drawn by me(lines,polygons) as a gif or jpeg file
image displaying from database with some other information imagedisplaying from database with some other information hi,
in the following section of code when i am not displaying the image it is working properly but when i tried to display the image nothing is displayed on browser
resize image with the change in size of jpanel.. - Java Beginners
resize image with the change in size of jpanel.. hi..
i am try to insert image in jpanel in jform to give attractive look to application,but the of image do not changes if the size of jframe or jpanel changes.
if there is any
Displaying image when clicked on URL in jsp - JSP-Servlet Displayingimage when clicked on URL in jsp Hi,
I am using... in displaying the image from the folder.
Regards,
Anish... For Screenshot : abc.jpg
here abc.jpg is a url and when clicked would show me an image
JTABLE SCROLL PANE
JTABLE SCROLL PANE The scrollpane for a image in Jtable is only showing but not working ....here is the code i am doing please suggest something...[]={"NAME","Address","Contact","Email","IMAGE"};
Object[][] data=new Object[50
JTABLE SCROLL PANE
JTABLE SCROLL PANE The scrollpane for a image in Jtable is only showing but not working ....here is the code i am doing please suggest something...[]={"NAME","Address","Contact","Email","IMAGE"};
Object[][] data=new Object[50
insert image using hibernate
insert imageusing hibernate Sir,
Today I hadposted question regarding upload image, th answer you had given is using SQL, but I am using Hibernate to insert data in the same table where I want to insert image.
Plz hlp me
How to Set Transperent Background Image to Jpanel - Java Beginners
How to Set Transperent Background Image to Jpanel Sir ,How to set Background Image to Jpanel. Hi Friend,
Try the following code...);
}
} );
JTextArea area=new JTextArea(15,4){
ImageIcon image = new
displaying data displaying data how to display data from database on jsp using struts2
Displaying images using Javascript Displaying images using
Javascript... to display images using javascript and css.For this we are going to make program named
image-slideshow-5.
css,image-slideshow-5.html,image-slideshow-5.js.The code
Display message on scroll Event
Display message on scroll Event
In this tutorial, we will discuss about how to display message on scrolling
of text area using jQuery scroll event. In this example, a text area with scroll
bars are given , when we scroll any one
JPanel - Drawing Area
Java: JPanel - Drawing Area
To use a JPanel for graphics
Define a new class that extends JPanel and define
a paintComponent method...;
Example of drawing panel drawing area.
Define a subclass of JPanel
The scroll browser event of jQuery
The scroll browser event of jQuery
In this tutorial ,we will print message on browser's window scrolling usingscroll browser event of jQuery. In this example, some paragraphs are written ,
when we scroll down, a message
Displaying html code in pdf with itext - Java Beginners Displaying html code in pdf with itext
Hi ,
I am geeting data which was enterd from fck editor. same data is stored in the database i need to display this data in the pdf .
i am using itext to create
How to save JPanel as gif or jpeg file
How to save JPanel as gif or jpeg file i draw polygons , rectangles, lines on jpanelusing draw line method drawpolygon methods etc, now i want save the data of jpanel which is drawn by me(lines,polygons) as a gif or jpeg file
Create a Scroll Pane Container in Java
Create a Scroll Pane Container in Java
 ... to create a scroll
pane container in Java Swing. When you simply create a Text Area... for the result
of the given program:
This program shows a scroll pane
Create Scroll Bar in Java using SWT
Create Scroll Bar in Java using SWT
This section is all about creating scroll bar in Java SWT
The given example will show you how to create scroll bar in Java using
Browse an image
Browse an image hi................
i want to browse an image from... this?????
i am using java swing.........
import java.sql.*;
import... java.awt.event.*;
public class UploadImage extends JFrame {
Image img;
JTextField
AWT Image
AWT Image I have loaded two images using toolkit in java.one... javax.swing.*;
import java.awt.event.*;
class DrawRectAndCir extends JPanel..., 20);
}
}
public class DrawConcentricRectangleAndCircles extends JPanel
xml displaying a drives data.....
xml displaying a drives data..... Hi all,
I need a solution for displaying content of a drive(Ex: c , d , e ) in the browser using the XML... a solution for displaying content of a drive(Ex: c , d , e ) in the browser using
Image Demo Image Demo
This section simply display the image demo that means
multiple images and its name are based on the frame to a particular location.
For displaying images demo
Scroll ImagesUIScrollView Scroll ImagesUIScrollView Hi, Can anyone please suggest me how to scroll images in UIScrollView in iPad?
THanks
image on div or cell of table image on div or cell of table I am using ms access database and I have stored the image in access database and I have a code to display image... send me the code for displayingimage from access database condition
image on div or cell of table image on div or cell of table I am using ms access database and I have stored the image in access database and I have a code to display image... send me the code for displayingimage from access database condition
image on div or cell of table image on div or cell of table I am using ms access database and I have stored the image in access database and I have a code to display image... send me the code for displayingimage from access database condition
image on div or cell of table image on div or cell of table I am using ms access database and I have stored the image in access database and I have a code to display image... send me the code for displayingimage from access database condition
image on div or cell of table image on div or cell of table I am using ms access database and I have stored the image in access database and I have a code to display image... send me the code for displayingimage from access database condition
image on div or cell of table image on div or cell of table I am using ms access database and I have stored the image in access database and I have a code to display image... send me the code for displayingimage from access database condition
Show spinner while loading image using JavaScript
Show spinner while loading imageusing JavaScript Hello sir
I am working on a web page which has .png image in middle of it. Other part of the page... and looks exactly the same as before except for the chart in the middle of the page
displaying in ajax - Ajax displaying in ajax hi..
I have an Ajax page ,request gone to server ana details are bought...
the response should be displayed in the same request page not in the other page...
Thank u..
I will be waiting
Displaying files on selection of date. Displaying files on selection of date. Hi,
I am developing a GUI, where i select from and to date. On selection of from and to date the GUI should... for same.
Here is a java swing code that accepts two dates and search
Displaying Hello World using GWT Displaying Hello World using GWT
This example describes the process for displaying... involved in displaying the Hello World message using Net Beans
IDE 6.1
hibernate image Upload
hibernate image Upload Sir,
I had posted question regarding upload image, th answer you had given is using SQL, but I am using Hibernate to insert data in the same table where I want to insert image. Plz hlp me. Thanks
pre view of image uploaded
pre view of image uploaded I am uploading a file through input type="file" in html form. I want to display preview of that uploaded image in the same form using java script only.. and I want to insert that image into oracle
pre view of image uploaded
pre view of image uploaded I am uploading a file through in html form. I want to display preview of that uploaded image in the same form using java script only.. and I want to insert that image into oracle database
I don't want