Can't Draw Very Far In A JPanel

Apr 16, 2015

I have a JPanel embedded in a JScrollPane. I draw in the JPanel, using the paint() method. I have to draw some shapes that can go far in the y direction, that's why I put my JPanel in a scroll pane, in order to scroll down to be able to discover the shapes down. But even though I put my JPanel in a JScrollPane, it soon blocks in the y direction and does not show the shapes far in the y direction.

Note: I used a GridBagConstraints which is correctly set, with its fill attribute etc.

View Replies


ADVERTISEMENT

Draw Panel On A Frame - Can't See JPanel

Apr 14, 2015

I've been trying to draw a panel on a frame with simple drawString drawRect and oval but when i run it the frame shows up with the exit on close stuff but nothing will show inside . this is my code :

import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.JFrame;
class Draw extends JPanel{
public void paintcomponents(Graphics g){
super.paintComponent(g);
g.drawLine(10,15,20,30);

[Code] .....

I'm not sure what's wrong , probably something to do from this pc ? since in the lab work at uni it worked fine .

View Replies View Related

How To Draw Multiple Graphics Inside One JPanel Using Multiple Classes

May 5, 2015

I'm very new to Java, and I am creating a program that takes multiple user input to create one face. I have a class for the eyes, nose, lips, and headshape. For some reason, my program is not drawing the graphics. ***for question purposes, I have only included my head shape class and my test class****

my "test" class:

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class FaceTest
{
public static void main(String[] args)
{
String head = JOptionPane.showInputDialog("Would you like a circle, square, rectangle shaped head?: ");

[Code] ....

View Replies View Related

Loading JPanel From Another JPanel When Button Is Pressed

Jun 9, 2014

I am making a game in java and i want to make a title screen. What I am trying to do is make a jpanel and load another jpanel when a button is pressed in one of the japenls. Here is the code for the runner

import java.awt.BorderLayout;
import javax.swing.JFrame;
public class Runner extends JFrame {
// Have these set up so they can be seen everywhere
public static final int GAMEWIDTH = 540;
public static final int GAMEHEIGHT = 710;
static boolean loading = false;

[Code] ....

here is the code for the jpanel that loads the other jpanel

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;

[Code] ...

How do load a jpanel when a button is pressed in another jpanel

View Replies View Related

NullPointerException Adding JPanel To JPanel

Jun 17, 2014

I have a Main() class that extends JPanel and I'm trying to add Card() that also extends JPanel.When I add a Card() or Main() object to the JFrame directly, it works fine. The problem arises when I try to add a Card() object to the Main() object.

I edited the code a little bit to make it easier to read so hopefully it's fine.

Main() code:
public class Main extends JPanel implements Runnable {
// HARDCODED OPTIONS
public static final int WIN_WIDTH = 1200;
public static final int WIN_HEIGHT = 800;

public static final int GRID_X = 9;
public static final int GRID_Y = 5;

[Code] ...

View Replies View Related

Draw Rectangle Through ArrayList

Oct 30, 2014

So I also am working on this problem. My frame does print each new rectangle; however, it is printed each time from the top left corner, and the bottom right is where I click.

Here is my RectangleComponent:

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Shape;
import java.util.ArrayList;
import javax.swing.JComponent;
public class RectangleComponent extends JComponent

[Code] ....

View Replies View Related

How To Draw Some Item Not Immediately After Run

Jan 21, 2014

So I drew a menu in DrawingPanel extends JPanel, that gets user input of number of players...etc. I also have a boolean, when true, the board is drawn, but apparently, right when I run, the boolean is checked, returns false and so board isn't drawn at all. When the user finishes input, the boolean becomes true, but the board doesn't get drawn. So my question is, how do I draw something not immediately when the program is ran?

View Replies View Related

Draw Geometry Shapes 2

May 9, 2014

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
public class Game extends JPanel implements ActionListener, KeyListener{
Timer t = new Timer(5,this);
double x = 0, y = 0, velx = 0, vely = 0;

[Code] .....

So why doesn't it work and what about the second dot.... ?

View Replies View Related

Draw From Bottom Of Bounds?

May 26, 2014

I 'm trying to draw a button by resizing a simple button background image to fit the size of the text. Everything works well except for the actual drawing of the string. The y value that I give the Graphics object designates the baseline, however I would like to draw the the string above the y. So that the image below doesn't happen.

I gave the graphics object the y of the bottom of the "P" and would instead like to give it the value of the bottom of the "y". Is there a way to do that by reading the String's bounds or something, or is there a way to get the Graphics object to use the passed y value as the definite bottom of the String?

View Replies View Related

Graph In Java - How To Draw Curve

Apr 8, 2014

If I have a function for example y=x^2

How can I draw the curve?

View Replies View Related

Dragging Mouse To Draw A Line

May 16, 2014

I'm doing a exercise for dragging mouse to draw a line. I found a code to do this, but I don't know something in the code. example array Shape in the code.

import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;

[Code] ....

View Replies View Related

Draw Sequential Diagram Using Java

May 14, 2014

draw a sequential diagram using java.with out using any other tool or plugins.

View Replies View Related

Draw JButton Over Background Image

Aug 3, 2014

I've tried multiple things but I can't seem to figure out how to get my JButton over the background graphics. On lines 104-108 I create the JButton I need to put on the screen, though I have no clue how to draw it. How I can paint over this background and have my button stay there?

public static final int WIDTH = 1024;
public static final int HEIGHT = 640;
private Thread thread;
private boolean running;
private BufferedImage image;
private Graphics2D g;

[Code] .....

View Replies View Related

Draw Ascending Stairs Using For Loops

Sep 27, 2014

I'm not looking for answers, well I am.. but not just straight given to me. I'm trying to learn but for this program I'm not even sure where to start. One step looks like this:

O *******
/| * *
/ * *
************

It must increase by a constant named STEPS. They ascend from left and go up right.

I'm just gonna start asking some questions I guess. Before I do anything I wanted to know whether I should have the stick man on the step drawn out with print and println statements or try to have him drawn with a loop as well? I'm not sure if my teacher wants everything drawn by characters with loops for each character, or if I can do print statements and draw the stick figure plus some stars and have a loop for multiple characters at once.

View Replies View Related

Draw Square With Asterisks (for Loops)

Apr 21, 2015

So currently I'm trying to learn how to draw a square with asterisks based on the input I give for it's sideLength.

So if I have a Square(5) it should draw a 5x5 looking like this:

*****
*****
*****
*****
*****

but then in the main method, it should draw multiple squares of given sizes, so say 5, 6, and 7. Making a square for each of the given numbers. This is what I currently have so far ....

class Square {
int sideLength; Square( int size ) {
sideLength= size;
} int getArea() {
return sideLength * sideLength;

[Code] ....

View Replies View Related

How To Draw Points With Coordinates From Database

Jul 23, 2014

I extracted columns from database and made calculations inside while loop. I know i need to make array to get from it coordinates for points. I want to draw them in interface created in another class but i have black hole and don't know how to get datas from while loop to array which is below.

View Replies View Related

Tic Tac Toe - Adding Draw System / Game Over

Jul 31, 2014

I have been trying to add a draw system to my code so far once all the boxes have been taken it does not tell the player its a draw game over. I have tried and deleted some code but I have commented some stuff that did'nt work at the bottom and also the X's and O's can be replaced in the same spaces?

import java.util.*;
//import for scanner
public class NoughtsAndCrosses {
public static int row,col; //integer for rows and columns
public static Scanner scan = new Scanner(System.in); //Scans the program
public static char[][] board = new char [4][4]; //Characters for the board set out 4/4

[Code] .....

View Replies View Related

Swing/AWT/SWT :: How To Draw A Diamond Using Polygon

Mar 8, 2015

I'm currently trying to do a diamond using Polygon. I have done this so far. It is not drawing a diamond.

import java.applet.Applet;
import java.awt.Graphics;

public class Diamond extends Applet {

int[] a = {-30, 100 , 30, 100};
int[] b = {100, 40, 100, -40};

public void init()
{
}
public void paint(Graphics g)
{
g.drawPolygon(a, b, 4);
}

View Replies View Related

XML :: Draw A Graph And Display It In The Mail

Jul 3, 2013

I have few values for X and Y axis from the Oracle DB table. SO is there any java technology available to display the values in the form of graph with the valuesfrom the table along X and Y axis and represent it in any form of graph , which we could chose.

View Replies View Related

Swing/AWT/SWT :: Iterating Through Objects To Draw On Panel?

Apr 23, 2014

I currently have the code set up to iterate through objects and keep track of them but how do I do the same and draw the objects on the panel window? I'm confused on what to do and how to start it.

Here's the code I have so far, the 'Car' which I want to draw extends to another class which extends to GameObject. I currently have a 'draw()' method under the 'Car' class but nothing in the 'draw()' method yet. From what I understand i'm suppose to have a 'draw()' method under 'GameObjects' class also?

public class MapView extends JPanel implements IObserver, ActionListener{
JPanel myPanel;
private Timer timer = new Timer(5, this);
int x = 0;
int moveX = 2;
public MapView(){
super.setBorder(BorderFactory.createTitledBorder("Map:"));

[code]....

Mostly I don't understand how to go through the iterator again to paint the objects. Wouldn't I need to put another iterator under 'paintComponent()' or can it be done under 'update()' ?

how to get some shapes from the GameObjects onto my panel.

View Replies View Related

Swing/AWT/SWT :: Draw String Inside A Shape

Mar 19, 2015

I have this piece of code, i want to insert a text inside my shape.

import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;

[Code] ....

View Replies View Related

Picture Draw (Roses) Using Polar Functions

Feb 23, 2015

I'm trying to make a code that will draw "roses" using polar functions. The code below is what I have, but when I run it nothing happens. What's missing?

package rose;
import edu.princeton.cs.StdDraw;
public class Rose {
public static void main(String [] args) {
int N = Integer.parseInt(args[0]);
StdDraw.setCanvasSize(512, 512);

[Code] .....

View Replies View Related

Using Jslider To Draw Rectangle In JTextField In Different Colors?

May 15, 2014

[color]
public class MyColorChooser extends JPanel implements ChangeListener{
private JSlider redSlider;
private JSlider greenSlider;
private JSlider blueSlider;
private JTextField txt1;
private JTextField txt2;
private JTextField txt3;
private final Color[] colorValues =

[code]....

Do i have to make a new no argument constructor for my sliders?

View Replies View Related

Reading Image From Folder And Draw It On Jlabel

Jul 1, 2014

I'm trying to read images and draw them on JLabel. This code snippet below is reading images from a folder

private ArrayList<ShowItem> getData() {
int score = 0;
ArrayList<ShowItem> item = new ArrayList<ShowItem>();
File dir = new File(getImageFolderPath());
if (dir.isDirectory()) {
for (final File f : dir.listFiles(IMAGE_FILTER)) {
BufferedImage img = null;
try {

[Code]...

ShowItem is a class that extends Image. DisplayImage extends ShowItem.

One of the overridden methods in ShowItem is

@Override
public Graphics getGraphics() {
return null;
}

I'm not exactly sure what to do here so I left it.

In another class, where I draw the images on Jlabel. This is what I have:

ShowItem theImage;
private ArrayList<ShowItem> listofImages;
theImage = listofImages.get(random.nextInt(listofImages.size()));
ImageIcon icon = new ImageIcon(theImage);
label.setIcon(icon);

I tried to run it, and check if I'm actually getting the images, and did system out and it listed all the jpg images I have but it's not displaying on the panel.

View Replies View Related

Swing/AWT/SWT :: Need To Draw JButton Such That It Displays On Top Of Two Different Panels

Mar 3, 2015

one of the java swing challenge I am facing. Problem statement: there are two JPanels panel 1 and panel 2 placed on a JFrame one below the other as panel 2 below panel 1. Now, I need to put a JButton in any one of the panels such that this JButton displays half in panel 1 and half in panel 2.

View Replies View Related

Buffered Image Draw String Method

Apr 13, 2014

So I've got this class method:

private void createTextBox() {
Graphics g = Game.getG();
Font font = new Font(fontName, fontStyle, fontSize);
g.setFont(font);
height = BORDER_WIDTH*2 + g.getFontMetrics().getHeight();
int stringWidth = g.getFontMetrics().stringWidth(dialog);
width = BORDER_WIDTH*2 + stringWidth;

[Code] .....

This gets called when ever I want to create my Textbox object however what gets created is a purple box (i know that I have set the array elements to purple to begin with) however when I try to use the drawstring method to "draw a string" I get an image which looks like the gif below. I have changed the text size to various sizes but without success. The string is supposed to say "This is a test" but obviously it doesn't.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved