How To Create Insets For JPanel

May 6, 2014

Is there a way to create insets for the JPanel without using the GridBagLayout, or createEmptyBorder() because the panel already wants to have an etched border?

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: GridbagConstraints And Insets Errors In GUI

Feb 10, 2014

I have to build the attached GUI as exercise (exercise.jpg), but I am getting a lot of errors on the console. OK so the code is available on pastebin here: URL>...An excerpt of errors is attached. I don't understand why I get them. Basically the compiler is picking on new GridBagCostraints() and new Insets().

View Replies View Related

JPanel Class Won't Create JLabel

Jun 1, 2014

So I am making a JPanel with two JLabels and it isn't working right.

import java.awt.*;
import javax.swing.*;
public class IntroPanel extends JPanel
{
public IntroPanel() {
setBackground(Color.green);

[Code] ....

For some reason

JLabel 11 = new JLabel("Layout Manger Demonstration");
JLabel 12 = new JLabel ("Choose a tab to see an example of a layout manger.");

add(11);
add(12);

is not registering the JLabel or add functions.

View Replies View Related

Create JPanel As Image And Save To Desktop

Apr 17, 2014

I have coded to create jPanel as image and save to desktop but the image is saved only in my src folder in My Documents. Here is my code-

public static BufferedImage getScreenShot(Component component){
BufferedImage image= new BufferedImage(component.getWidth(),component.getHeight(),BufferedImage.TYPE_INT_RGB);
component.paint(image.getGraphics());

[Code] ....

View Replies View Related

Swing/AWT/SWT :: How To Create A JPanel That Maintains Same Aspect Ratio When Resized

Feb 23, 2014

I'm trying to create a chess program that uses a JPanel with an 8 by 8 grid layout with 64 jlabels with icons. However, I don't want the icons to be distorted if the user resizes the window in such a way that makes the panel not square. Is there any way I could create a JPanel that maintains a square aspect ratio when it is resized?

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

Create A Class That Will Accept Dates In Various Formats And Create A Range

Feb 1, 2014

In the class below I'm trying to create a class that will accept dates in various formats and create a range. The first constructor is easy because I send it the begin date and end date as Date objects. Now I want to send a month(and year) in a constructor and derive the begin and end dates from it. In my constructor that accepts the month/year I need to put the this(startDate, endDate) at the top to be allowed, but the parameters are not built yet.

package com.scg.athrowaway;
import java.util.Calendar;
import java.util.Date;
public class DateRange {
private Date startDate;
private Date endDate;

[code].....

View Replies View Related

Create A Menu Where The User Can Create A New Account?

Oct 5, 2014

I'm having some difficulty with my bank account project. I'm supposed to create a menu where the user can create a new account, withdraw, deposit, view their balance, and exit. There's issues with the account creation.

Here's my necessitated class below: BankAccount, TestBankAccount, SavingsAccount, CurrentAccount, and Bank

/*---------------------------------------------------
Plagiarism Statement
 
I certify that this assignment is my own work and that I have not copied in part or whole or otherwise plagiarized the work of other students and/or persons.
 
----------------------------------------------------------*/ 

package BankAccount;
 import java.util.Date;
import java.util.Random;
 //Project 3
public class BankAccount {
protected static int accountID;

[code]....

View Replies View Related

How To Get JPanel To Refresh

Mar 18, 2015

I have tried to get my JPanel to refresh and show a new combo box, labels and fields but I can't get it working with revalidate or repaint.

package Part4; 
import javax.swing.*;
 import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 public class AddressGUI extends JFrame implements ActionListener{
 Address address = new Address();

[code]...

View Replies View Related

How To Add Image In JPanel

Mar 18, 2015

how do i add image in JPanel

View Replies View Related

Second JPanel Not Working

Oct 14, 2014

I code a program using Eclipse Keppler with Java 8.0. I made a program with 2 JPanel. The first JPanel is working well. From a button in first JPanel, I excute second JPanel, but It is not working. No error when I compile the code. Here is, I attached the source code.

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

[code]....

View Replies View Related

JPanel Won't Show

May 8, 2015

I want my program to show 1st panel and when a person press image label 2nd panel showup which will have 2 tabs "oneway" and "round trip". But rightnow I only see 2nd panel with only 1 tab and don't see 1st panel at all.

import java.awt.*;
import static java.awt.Font.BOLD;
import java.awt.event.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.*;
import javax.swing.Timer;
import javax.swing.border.*;
import javax.swing.event.*;

[code]....

View Replies View Related

Fix Dimensions Of JPanel

Aug 27, 2014

I'm trying to fix the length of expenses to a appropriate size on my Jpanel but not sure how.

package mybudgetapp;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

[code]....

View Replies View Related

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 View Related

How To Add JScrollPane Into JPanel

Jan 16, 2015

As you can see in the above image. I have create One jFrame inside it their is one jPanel. Inside jPanel their are dynamic buttons whose range can change. (its like text box if you add more text scroll bar will appear)
 
I want to add jScrollBarr/jScollPane to jPanel so that when more than 6buttons will be their, I can scroll it down/up. So my question is how should I place jScollPane using this DRAG-DROP tool. When i clicked on jScrollPane and tried to put it inside jPanel I am unable to set it's position. It's my first time to add jScrollPane for jPanel inside jFrame.

View Replies View Related

JPanel Buttons Not Showing Up?

Feb 21, 2015

In my if statement on line 46 & 47 im trying to add the buttons to the screen if the player has lost and the "game over" screen have popped up. But the buttons aren't showing... what am i doing wrong?

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;

[code]...

View Replies View Related

JButtons Not Appearing In JPanel

Apr 17, 2014

I want to add a "play" and a "stop" button to stop and play a sound file. Sound file works good, but buttons aren't appearing in the window.

public class SpelaLjud extends JPanel implements ActionListener {
JButton bPlay, bStop;
AudioClip ac;
public SpelaLjud() {
bPlay = new JButton ("PLAY");
bStop = new JButton ("STOP");
add(bPlay);
add(bStop);
bPlay.addActionListener(this);
bStop.addActionListener(this);

[code]....

View Replies View Related

JPanel Is Not Displaying All The Time

Jul 2, 2014

Yes my JPanel is not displaying all the time like you would think it would. Before you beat me up yes I am a bit new I am just working on the GUI part of java over my summer break. Obviously it is not suppose to do that. Secondly, As you can see i am using the alphabet to create JButtons. Shouldnt there be an easier way to use a for( loop) . I tried before but I didn't want to get too side tracked.

Java Code:

import javax.swing.*;
import java.awt.*;
public class hello {
private JFrame alphaframe1;
private JFrame alphaframe2;

[Code] .....

View Replies View Related

Order Buttons In A JPanel

Sep 22, 2014

I'm learning the swing options of Java, and my first exercise was the typical Chat Room. I got everything right: TextField, TextArea, the jpanel at left side and the buttons inside of it. BUT I can't order the 2 buttons (1 north, 1 south). I've already looked for answers, but didn't find anything and I tried to asked the teacher, but she was too lazy to look for the error. Here is my code:

f=new JFrame("Chat Room");
b1=new JButton("Send");
b2=new JButton("Emoticons");
public void showWindow(){
p1=new JPanel();
f.getContentPane().add(p1,BorderLayout.EAST);
p1.add(b1,BorderLayout.NORTH);
p1.add(b2,BorderLayout.SOUTH);
}

View Replies View Related

Adding Object To JPanel

Nov 28, 2014

I am making a graph to implement Breadth First Search and Depth First Search. I changed the program because I want each button to be its own node. However I am having an issue placing them into a panel. When I run the program I get the following error:

The method add (Component) in the type Container is not applicable for the arguments (Buttons)

JPanel matrixPan(){
Buttons[][] matrixBtn = new Buttons[25][25];
JPanel panel = new JPanel();
panel.setSize(550,550);
panel.setLayout(new GridLayout(25,25));

[Code] .....

View Replies View Related

How To Move JLabel In JPanel

Jan 9, 2014

I am trying to move a JLabel in a JPanel, but can't seem to make it work. I can't provide a compiling code, but a few fragments. I have a JLabel [] array. i want to move with the mouse elements of this array. Let's say i want to move JLabel[i]. I implemented this:

Java Code:

static int labelY;
static Point labelX;
static Boolean flag = false;
jLabel[i].addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent evt){
labelY=evt.getY();

[Code]...

I used the bool flag because i can't make changes to the label when it is inside an anonymous class. I also tried using setLocation but that did not work also. I don't get any errors when compiling. But when i run it and try to drag the JLabel[i] i get a long list of errors:

Java Code:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at puzzle.hw$1$2.mouseDragged(hw.java:276)
at java.awt.Component.processMouseMotionEvent(Unknown Source)
at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)

[Code]...

View Replies View Related

Way To Rotate JPanel In Java

Jul 28, 2014

Is there any way to Rotate jPanel in java (without using Paint Function).

View Replies View Related

JPanel Appears To Be Null

Feb 23, 2014

I've a JPanel declared as a field in a JFrame:

public static javax.swing.JPanel pane;
I initialize it in a method (Well, Netbeans' GUI builder does. :P)
pane = new javax.swing.JPanel(){
@Override
public void paint(Graphics g){
g.setColor(Color.BLACK);
g.drawArc(8, 6, 15, 15, 0, 90); /* This works. The panel and frame are displayed, the arc is drawn, &c. */
}
};

it works and all; the arc is drawn.I want to draw on it dynamically by instantiating its Graphics (I call the "public Graphics getGraphics()" method.). This has worked for me before, taking a JPanel's Graphics and drawing with it through a different method than public void paint(Graphics g); But when I do, it comes up with a NullPointerException. WAIT! Don't go rambling on about initializing the variable because I've gotten past that NPE newbie's blockade.public static void render(Something s) { /*This is in a different file altogether. pane is public, static so I can access it from here. That's not the problem.*/

JPanel jp = Frame.pane;
Graphics g = jp.getGraphics();
g.fillRect(s.x, s.y, 4, 4);
}

Upon further investigation:
Exception in thread "main" java.lang.NullPointerException
at physics.Renderer.render(Renderer.java:30) <-- This line is "JPanel jp = Frame.pane;"
at physics.Renderer.renderall(Renderer.java:24) <--This line calls public static void render(Something s)
at physics.Updater.update(Updater.java:47) <--Renderer is just a tool used by the Updater. Sounds like a game loop, right?
at physics.Physics.main(Physics.java:31) <-- The game loop.

it says that Line 30, making jp and pointing it to pane itself is the problem.

Conclusion:
-The JPanel in the JFrame is created, initialized and overrides a parent method.
-The JPanel is not initialized, meaning that it is null. There is obviously a problem.

View Replies View Related

Opening Image In JPanel

Dec 18, 2014

I've been working on this code since a couple days and I just can't find what's wrong here. I have make an image open when the JMenu m6 button is clicked but it just doesn't work. I've tried a bunch of different codes but when I click on the desired button, nothing happens. Here's the code :

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Dimension;

[code]...

View Replies View Related

How To Use Images As Backgrounds For JPanel

May 20, 2014

I am trying to use images as my backgrounds for my JPanel.the problem is when I run the program the images don't show at first.T hey start to show after I have switched to another panel and then switch back. Here are my codes

//for loading image
static public Image LoadIcon(String file) {
URL icoURL = windows.class.getResource(file);
Image img = Toolkit.getDefaultToolkit().createImage(icoURL);
return img;

[Code] ......

View Replies View Related







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