jpanel

NullPointerException using Graphics2D in custom JPanel

I'm extending JPanel to make a custom drawing panel, but am getting a NullPointerException and can't work out why. I've removed code until it's pretty bare, but the error is still occuring. package testdraw; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import javax.swing.JPanel; public class Dr...

Java Swing - Background of a JPanel

I want to design a JPanel which should have the color coding as shown in the following diagram: How can I code the colors of a JPanel. What I think is that add 5 JPanels (for 5 blocks shown above) on a main JPanel. Set the background of each JPanel to light Gray. But then how can I achieve the dark color lines as shown in the diagram...

java simple JPanel management (see screenshot)

I have a JPanel that encapsulates two JPanels, one on top of the other. The first holds two JLabels which hold the playing cards. The second holds the player's text (name and score). However, when I remove the player's cards, the lower JPanel moves up to the top, which i would prefer that it not do. Is there a way to keep it in place...

What is the relation between ContentPane and JPanel?

I found one example in which buttons are added to panels (instances of JPanel) then panels are added to the the containers (instances generated by getContentPane) and then containers are, by the construction, included into the JFrame (the windows). I tried two things: I got rid of the containers. In more details, I added buttons to a...

Custom JComponent not displaying in Custom JPanel

I've tried the add() method but nothing is displayed when I try to add Test to GraphicsTest. How should I be adding it? Can someone show me? I've included the code I'm using. This is my way and it's not working. Can someone show me or make me aware of what the problem actually is? import java.awt.Color; import java.awt.Graphics; import...

Java JFrame method pack() problem

Hi, I have a frame with 4 JPanels and 1 JScrollPane, the 4 panels are in border layout north, east, south, west and the scrollpane in the center. I have been trying to get the pack method for a frame fuctioning but when run you just get the title bar of the window. Any Ideas? Thank you in advance. JFrame conFrame; JPanel panel...

Get two Jpanel expand in a JFrame asymmetrically.

Hi there. I have a JFrame with two JPanels inside. One is set on west, other on east with BorderLayout. The thing is, it just shows two 10 pixel width, 100% JFrame height strips: What i want to do is to setsize each panel having as end result that the jpanel on the west be 80% of the jframe width, the remaining 20% to the one on the ea...

Disable JPanel with visual effect

I'm looking for a good way to disable a JPanel. I'm using a MVC design for a Java Swing GUI. I want the JPanel to be disabled while the model is processing stuff. I've tried setEnabled(false). That disables user input on the JPanel, but I'd like it to be grayed out to add a more visual effect. Thanks in advance! ...

How do I remove an old JPanel and add a new one?

I would like to remove an old JPanel from the Window (JFrame) and add a new one. How should I do it? I tried the following: public static void showGUI() { JFrame frame = new JFrame("Colored Trails"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(partnerSelectionPanel); frame.setSize(600,400); ...

Why I cannot add a JPanel to JFrame?

Here is the code: import javax.swing.SwingUtilities; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JLabel; import java.awt.event.*; import java.awt.*; public class GameWindow { private String[] players; private JFrame frame; // Constructor. public GameWindow(String[] players) { this.players = players;...

How to set more panels in Java

I need to get two JPanels into one JApplet. paneel = new RekenmachinePaneel(); nummer = new NummerPaneel(); setContentPane(paneel); Now I need to get the nummer panel to show up beneath the paneel. How should I do that? ...

Can I add a component to a specific grid cell when a GridLayout is used?

When I set the GridLayout to the JPanel and then add something, it is added subsequently in the "text order" (from left to right, from top to bottom). But I want to add an element to a specific cell (in the i-th row in the j-th column). Is it possible? ...

What is the correct way to set size of elements of GUI?

I am using swing to create my GUI. J have a JFrame containing one main JPanel which, in its turn contain several JPanels which, in their turn, contain buttons. I would like to set certain sizes to mu buttons and JPanels. How does it work? Should I set sizes of my buttons and then the size of the JPanel and the JFrame will be set accordi...

How to rotate an image properly in JPanel (Java)

Hi guys, I'm working on rotating a loaded image. I set the graphics on a JPanel and then use standard AffineTransform in order to rotate it, say, 45 degrees. Unfortunately, the image is being cut, if it exceeds the panel area. How may I force JPanel to add scrolls to itself (while loading an image file, I would like to adjust the size...

two panel in java (first panel has fix size, second has remainder size)

I want some like this: http://eta.name/timages/JPanel_Layout.png (sorry, I have no reputation to post image) How make it ideologically correct? ...

jList in Scrollpane, seeking and displaying value of selectedIndex

I have a JList inside a Scrollpane. If you click on the list and move the arrow keys up and down it works like you expect, you can move your selection index and display around just fine. Now, what I want to do is basically have a text box and i'm typing in the text box like "comic" and want it to seek to the index of that value. This ...

Updating the Jpanel of a class

Hi, After some advice on using jpanel - I'm new to java and playing around with the GUI elements. Bascially what I'm curious about is if I can set up a Jpanel in one class, then somehow add labels etc to the that container, but from another class. Is this possible ? or do i have to set the entire GUI up in one class, but then I guess...

Why SetMinimumSize sets the minimal heights but not width?

Here is my code: import javax.swing.*; import java.awt.*; public class PanelModel { public static void main(String[] args) { JFrame frame = new JFrame("Colored Trails"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel...

How to set a Transparent Background of JPanel

Hi, I need to know if a JPanel`s bacground can be set to Transparent? My frame is has two Jpanels Image Panel and Feature Panel, Feature Panel is overlapping Image Panel, the Image Panel is working as a background and it is loading image from a remote Url, now I want to draw shaps on Feature Panel , but now Image Panel cannot be seen d...

Java JPanel not showing up....

I'm not sure what I am doing wrong, but the text for my JPanels is not showing up. I just get the question number text, but the question is not showing up. Any ideas what I am doing wrong? import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class NewFrame extends JFrame { JPanel centerpanel...