FAQ Database Discussion Community


java Swing: how to keep one component left aligned with another component centered with respect to parent

java,swing,layout,jpanel,layout-manager
Say I have two components, A and B, in a JPanel. I want Component A to stay left aligned, while Component B does its best to stay in the middle of the panel. I mocked up the following demo (sorry for the quality, I made it in paint): What I...

Add Object to JPanel after button click

java,swing,jpanel,add,jscrollpane
I have created a JScrollPane with a JPanel inside it and I want to add JPanel/JLabel/Other objects after pressing the button. For example after three button presses I want to get something like this: I tried myJPane.add(testLabel) with testlabel.setBounds()but no result, I don't want to use GridLayout because of the...

JFrame/JPanel refreshing and text fields

java,jframe,jpanel,refresh,textfield
I'm trying to switch between displaying different JPanels in BorderLayout.CENTER in a JFrame. The JPanels each contain a JTextField and a JTextPane. Calling revalidate() and repaint() on the JFrame, I get a very strange result: the first time I switch to secondPanel by clicking secondButton, everything works as expected. Then...

Dynamically add fixed-height panels to a JScrollPane

java,swing,jpanel,jscrollpane
JPanel panel = new JPanel(new GridLayout(0,1)); JScrollPane contentpane = new JScrollPane(panel); JButton add = new JButton("ADD"); add.actionListener(new ActionListener() { public void actionPerformed(){ MyPanel newpanel = new MyPanel("title","Button"); //MyPanel is a class which extends JPanel and contains constructor MyPanel(String TitleToSet ,String ButtonTitleTOAdd) panel.add(newpanel); panel.repaint(); }) ; I have used this code...

JPanel API: Perhaps the stupidest to ever grace Stackoverflow

java,inheritance,jpanel
So I was reading the JPanel API and saw the fields about inherited methods for example, and I saw three boxes of methods that JPanel inherits. Now, knowing what I learned the first week of the Comp. Sci. intro class, JPanel can only inherit methods from its superclass, so then...

Problems with detecting mouseClick in a JPanel and preventing circle from painting in JPanel

java,swing,jframe,jpanel
My current program lets the user move a circle around the JFrame and also change its color by pressing one of the colors presented in the JPanel at the bottom of the JFrame. My code: import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.border.Border; import javax.swing.BorderFactory; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import...

How can I make the pixels in this JPanel dynamically change?

java,jpanel
I have designed a program that outputs 1x1 rectangles (That I'll from now on call Pixels) with a color that is randomized between a random variable between Red, Green, and Blue. Now I want to take it one step further. First off, here's the source: public class GUI extends JPanel...

Trying to figure out the CardLayout

java,swing,jpanel,layout-manager,cardlayout
I'm trying to work out how to use the CardLayout but I keep getting "wrong parent for CardLayout" errors and such. I've never used CardLayout before and I can't seem to find a lot online. I just need to be able to switch between two panels on the frame. Thanks...

Why is paintComponent not displaying correctly?

java,swing,jpanel,paintcomponent
When running my program, sometimes the the triangles are drawn, sometimes they aren't, and sometimes only the last one appears. Originally I put the code in a for loop, but it didn't work, so I tried to go backwards and write it all out instead to see if it works,...

How to prevent the JPanel from being updated?

java,swing,graphics,jpanel
I'm creating a sort of paint application. The user can move a circle in a JPanel by pressing/dragging the mouse. I have a JCheckBoxMenuItem in one of my JMenus: JCheckBoxMenuItem checkitem = new JCheckBoxMenuItem("Draw mode",false); When it is not activated, the circle can only be moved (by dragging/pressing) and the...

How do I center a JPanel containing a FlowLayout?

java,swing,jpanel,layout-manager
I have a JPanel containing a few components, laying them out with a FlowLayout, so that they will wrap if necessary and i want to center this JPanel in a JFrame. I tried to use a BoxLayout with a VerticalGlue, but it doesn't center it completely. Here is a simple...

Circle drawn in a JPanel does not get drawn at the position of mouseClick

java,swing,jpanel,mouseevent
I'm trying to create a program that lets the user move a circle in a JPanel, But I'm facing some problems. My program: import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.border.Border; import javax.swing.BorderFactory; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.Color; import java.awt.Graphics; import java.awt.FlowLayout; import...

Avoid JPanel from getting over another

java,swing,jpanel,layout-manager,border-layout
I'm trying to load JPanels inside another but I can see only one, the others get hidden behind it. This is my code: pnlResultados.setLayout(new java.awt.BorderLayout()); for (int i = 0; i < cantResultados; i++) { pResultado pr = new pResultado(modelo, resultados.get(i), padre, this); System.out.println("panel"); pnlResultados.add(pr); pr.setVisible(true); } pnlResultados.setVisible(true); pnlResultados.revalidate(); pnlResultados.repaint();...

Trying to draw lines based on doubles but nothing shows?

java,swing,jpanel,double,graphics2d
Here's the class in which I try to draw the lines package gps; import java.awt.*; import java.awt.geom.Line2D; import java.util.*; import javax.swing.*; public class RoadMap extends JPanel { public void paintComponent(Graphics2D g) { super.paintComponent(g); g.setColor(Color.blue); for(int i = 0; i < Graph.getEdges().length; i++) { Shape s = new Line2D.Double(Graph.vMap.get(Graph.getEdges()[i].i1).x, Graph.vMap.get(Graph.getEdges()[i].i1).y, Graph.vMap.get(Graph.getEdges()[i].i2).x,...

Java GridBagLayout JPanels automatically resizing issue?

java,swing,jpanel,jlabel,gridbaglayout
I need a help with a resizing of Red coloured JPanel. Basically the problem is that I set the grid bag constraints for RED and BLUE JPanel same size and it works perfect, until i add the JLabel, then it just stupidly starts making the RED JPanel Larger size, but...

Can't paint on JPanel after clearRect() and repaint()

java,swing,jframe,jpanel,paint
I have a program which lets the user paint. But when the user clicks the clear button which calls clearRect() and repaint() the user can no longer keep painting on the same panel. Another issue I am having is that when the user clicks the save or open button (which...

How to add a jbutton to a jpanel

java,swing,jpanel,jbutton,jscrollpane
I've trying (unsuccessfully) to add loop generated JButtons to a JPanel. The thing is that the JPanel is over JScrollPane. Here is my code: String categoria = this.cmbCategoria.getSelectedItem().toString(); String[] partidos = myEstadio.buscarPartidos(categoria).split("/"); JButton b; for(String p : partidos){ b = new JButton(p); this.panelScroll.add(b, BorderLayout.CENTER); System.out.println(p); System.out.println(b.getLocationOnScreen()); As you can see,...

Own Coordinates for JPanels

java,swing,jpanel
Code: for(int i=0;i<10;i++) { for(int j=0;j<10;j++) { JPanel panel = new JPanel(); addListener(panel); panel.setBorder(new LineBorder(Color.black,1)); grid.add(panel); - public void addListener(JPanel p) { p.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { System.out.println(panelX); System.out.println(panelY); } }); How can I set a X-coordinate and a Y-coordinate for each panel? (If i = 5...

JScrollPane will not work no matter what Panel or Container I assign it to

java,swing,jpanel,jscrollpane
So I've been trying to get a JScrollPane to work on my page but it just wont! I have a table that goes beyond the bounds set and Im trying to set it up so I can scroll down and view everything. I have tried adding the JScrollPane to all...

JPanel does not show until after the code

java,swing,jpanel,event-dispatch-thread
What I want to do is to show a new panel with a progress bar while the process takes place. My code is as follows: case "GoButton": cards.show(this, "pp"); this.test(); cards.show(this, "panel1"); break; That is in a actionPerformed method but when I run the program it just ignores the first...

Swing Panel in Panel different Layouts

java,swing,jpanel,layout-manager
I'm quite new to Swing and Java. What I tried to accomplish is panel containing and textfield and below some tags (JLabel). Unfortunately I am not allowed to post images yet. So here's a scribble of the layout I want to create and what I get: https://www.dropbox.com/s/xsfwijlp77xssmk/panel-in-panel.png?dl=0 add(textFieldTags); tagWrapperPanel =...

Customizing JPanel with Sea Glass Look and Feel

java,swing,jpanel,look-and-feel,seaglass
I have a JFrame and a JPanel. I have added my JPanel onto my JFrame. I am using Sea Glass Look and Feel. My JPanel has a title and a border created through the following code : panel.setBorder(BorderFactory.createTitledBorder("Titled Panel")); The problem is when I run my program with Sea Glass...

Components get squished in JPanel and JFrame

java,swing,jpanel,null-layout-manager
I'm trying to create a GUI window for the user to enter some information for my program. But it seems like no matter how I change the sizes or the locations, all of my components are squished in far smaller than what I want. Could someone please point out what...

Java actionPerformed questions

java,swing,jframe,jpanel,action
Hello everyone I am new to java programming and I begin to fell in love with making simple JPanel or JFrame games. But recently I'm starting to challenge myself on writing a more complicated game called "Doodle jump". As most of you may already heard of this game you are...

More than 2 Visible JPanels in a CardLayout

java,swing,jpanel,layout-manager,cardlayout
I am facing problems while placing more than two JPanel objects in a CardLayout which are visible at the same time. Although I can place a number of panels, but they do not appear simultaneously and I cannot resize them as I want. For a more clearer view about what...

java.lang.ArrayStoreException with new JPanel

java,swing,exception,jpanel
I have a problem: public static JPanel regNewBodyPart(int i, int x, int y){ //System.out.println(i); body[i] = new SnakeBlock(); JPanel bp = body[i]; //bp.setBackground(Color.GREEN); bp.setBounds(x, y, 20, 20); bp.setVisible(true); registeredBodyParts++; return(bp); } Throws an java.lang.ArrayStoreException, when I change body[i] = new SnakeBlock(); to body[i] = new Block(); does not. I dont...

JPanel with JSlider not displaing the Graphics

java,swing,jpanel,jslider
All i have is a JPanel with a white background and the JSlider on the bottom, not displaying the square, i think i have made some mistake with the JPanel class but i can't figure it out. Just before i made another project with g.fillOval and it worked properly, i...

Displaying Image Inside of Original GUI Frame

java,swing,jpanel
I have a GUI form called SimpleGUI that is just a single JPanel. My goal is to display my URL image inside of the that JPanel. When I try to add the image, I don't get an error, but nothing displays. The image DOES display if I create a new...

How to make components in a JPanel strectch as far as possible?

java,swing,jpanel,components,layout-manager
I'm trying to create a simple swing program that lets the user play with a circle. Here is my code: import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.border.Border; import javax.swing.BorderFactory; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.Color; import java.awt.Graphics; import java.awt.FlowLayout; import java.awt.BorderLayout; public class SixthProgram { public static...

Why is my repaint method not repainting?

java,swing,jpanel,paint,repaint
I am not sure why, but for some reason my repaint method is not working. I know that the movement is correctly working because I also have println(); statements to help me check. I am not sure if it because of how I am painting my character onto the JPanel,...

add jPanels by selecting jCheckBoxes

java,swing,jpanel,jcheckbox,netbeans-8
As you can see from layout I want to add (or show) jPanels by selecting checkBoxes. panelWindow is enclosed in jScrollPane. + checkBox1 | jPanel1 | ------------------------------------- + checkBox2 | jPanel2 | ------------------------------------- + checkBox3 | jPanel3 | ------------------------------------- ^ ^ | | checkBoxPanel panelWindow In the case when selected...

JPanel disappears when added to more than one other JPanel

java,user-interface,jpanel,jbutton,boxlayout
Hopefully you all can help me understand this mystery. I created a JPanel that contained a "Go Back" button and had a nice layout that I liked. I wanted to add this JPanel (I'll call it homeButtonPanel from here on out) to several other JPanels because I want them all...

Mouse detection at many positions

java,swing,jpanel,mouseevent
I am using Java with Swing and I want to detect mouse clicks at a number of locations (~200) in the view. Should I use coordinates to ascertain where the click occurs (requiring searching through every location) or add multiple JPanels over each location and listen for mouse events for...

GUI not drawing on drawpanel?

java,swing,jpanel,paintcomponent
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class SimpleGui3C implements ActionListener{ JFrame frame; public static void main (String[] args){ SimpleGui3C gui = new SimpleGui3C(); gui.go(); } public void go() { frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Change colours"); button.addActionListener(this); MyDrawPanel drawPanel = new MyDrawPanel(); frame.getContentPane().add(BorderLayout.SOUTH, button); frame.getContentPane().add(BorderLayout.CENTER,...

How to put a JButton at a specific location?

java,swing,jframe,jpanel,jbutton
I know that there are already very similar questions to my question on stackoverflow, but neither one of them answers my question. I want to put my JButton on a specific location on my JFrame in JAVA. Here is my Code: public class DetectMotion extends JFrame { private JLabel label...

Java BufferedImage / JPanel not updating new black pixel rows using JButton

java,swing,jpanel,bufferedimage,paintcomponent
Basically I have a (width x height) size of pixels in a buffered image and would like to draw simple horizontal BLACK lines, one after another into the Buffered Image / JPanel. Each click of the button should create a new horizontal line. Although the button event reaches the updateImage()...

Converting JFrame to JPanel

java,swing,jframe,jpanel
I currently have written some Java Swing using a JFrame and it works fine. But now I need to use multiple screens and they are done using cardlayouts. So i need to convert my JFrame to JPanel. Currently I have this line for my JFrame mainFrame.getContentPane().add(c4Panel,BorderLayout.CENTER); But if I convert...

Tileing image on JPanel, java

java,swing,jpanel
I have a method to set the 'texture' of a JPanel, however it is throwing a NullPointerException, and i cannot figure out why. Method: void setTexutre(Image tileImage) { Graphics g = panel.getGraphics(); int width = (int) getBounds().getWidth(); int height = (int) getBounds().getHeight(); int imageW = tileImage.getWidth(panel); int imageH = tileImage.getHeight(panel);...

JFrame text components not showing up properly

java,swing,jpanel,layout-manager,preferredsize
I was playing around with JFrame today and had trouble getting a JButton component to display text properly. The text displayed in JButton is cut off at the end. I tried resizing the JButton component in order to make sure that the text could fit, but the same problem occurred....

How to set a single background for all panels in CardLayout? [closed]

java,image,swing,jpanel
I am designing an application in Netbeans using CardLayout & I want to use the same background for all of my JPanel objects. I have already tried to accomplish what I want using the method discussed in How to add an image to a JPanel?, however I haven't figured out...

JSlider changeListener won't update - Java

java,swing,jpanel,repaint,jslider
I have a fractal tree generator and I am trying to make a slider control the number of iterations, but I can not get it to work. Also, the layout gets messed up whenever the repaint() method is called. Any thoughts on how to fix this? public class FractalTree extends...

Draw in another component

java,swing,jpanel,components
I have a homework to do but there is not enough information and I'm stuck right now... Here is the issue, I have three classes : "ChoicePanel" extends JPanel and add buttons to select a color with a JComboBox public class ChoicePanel extends JPanel{ Draw dessin; public ChoicePanel(Draw df) {...

jPanel not showing up inside jLayeredPane

java,swing,dynamic,jpanel,jlayeredpane
I've read all the topics regarding this issue,and i can't figure out what's the problem. The following code is inside a method that gets called on button click, the buttons were dynamically generated, and yes the console output is showing, so the method is getting called. System.out.println("loaditems method"); final JPanel...

JPanel size is not known on start

java,swing,jframe,jpanel
When I create a Board instance from my Square instance, I try to assign the size of the window to the integers x and y. I fail to do this because it seems like on start the size is 0. In the constructor in Board.java, x and y shouldn't be...

Java and JFreechart panel

java,jpanel,jfreechart
I have put together the code below. Currently as soon as I run the file the graph is created in the JFrame/Jpanel depending if I use handleb1 or handleb2. My aim is upon running the file a frame is created with a chart that doesn't hold any values, but the...

How do I continue to paint on an image after redrawing it?

java,swing,jpanel,bufferedimage,paintcomponent
My program is meant to let a user paint on a bufferedimage and open/save files to paint on. After I open the bufferedimage I saved, I cannot continue to paint on it. Below is my code. Any other suggestions for moving around code or making it simpler would be appreciated....

Put 2 FlowLayouts one under another with a margin

java,swing,jpanel,layout-manager,flowlayout
I'm trying to dynamically create 2 FlowLayout instances (one of them has about 50 dynamically created buttons, other has about 10) so that there is a slight gap between them. I'm stuck with this, I tried to use BoxLayout and put flow layouts in it, and then create gap with...

Why cant i paint on the panel

java,swing,jpanel,awt,drawing
I have made three panels south, east and north, i am trying to draw a circle on the north panel but i just cant figure out why it is not drawing.Here is my code: What i want is a small application that draws circles of different sizes and colours chosen...

resize synchronously jPanel components

java,swing,layout,jpanel,layout-manager
I have a JFrame as follows: -------------------------| |JFrame | | | | |---------------------| | |JScrollPane | | | |jXTaskPaneContainer| | | |jXTaskPane | | | | |-----------------| | | | |jPanel1 | | | | |-----------------| -------------------------| Below you can see the layout of jPanel1: | label1 | (without title)...

How does repaint() work when I have multiple JPanel objects in a single JFrame?

java,swing,jpanel,paintcomponent,repaint
I have read that when a JPanel object (or any instance of a class that extends JPanel) is part of a JFrame, each time the JVM thinks that the JFrame needs to be refreshed, the JPanel instance's paintComponent() method is called. But what happens when I have two such objects,...

load JPanel that contains another JPanel

java,swing,jpanel,containers
I'm trying to load a Class that extends JPanel and has components from another Class that also extends JPanel into another Class. And this is what i need to achieve: Example of First.java public class First extends JPanel{ JPanel cont = new JPanel(); public First(){ cont.setBackground(Color.YELLOW); } } Example of...

Custom JPanel causing rendering problems in second custom JPanel

java,swing,jpanel,paintcomponent
Bit of an odd one here. I have two classes extending from JPanel, overriding paintComponent in both. One implements Runnable (for animation purposes). However, when used together with the Runnable one on top, I get the wonderful "paint a copy of everything the mouse points at" in the background of...

How to paint over a JPanel?

java,swing,graphics,nullpointerexception,jpanel
I (A novice programmer) am trying to paint an oval over a JPanel. I am trying to use the method paint. However, it requires a Graphics argument. I get a NullPointerException when I include my Graphics as a argument because it is null, but I do not know how else...

Java Swing Panel displaying image strange behaviour

java,image,swing,jpanel
I have no idea what the heck is going on while I'm trying to render an image on a JPanel in a JFrame. In fact I just want an image displayed in a fixed position on my JFrame.To achieve this I have a JPanel of a fixed size (min, max,...

JPanel help- Drawing rectangles

java,jframe,jpanel
I'm using Graphics for the first time but I have an issue where nothing is showing up besides the background (identified as Bcolor). I'm trying to make a grid with lines using fill(new Rectangle) method with color Lcolor. I ran the debugger, and there doesn't seem to be any syntax,...

Add dynamic buttons to jpanel in Java

java,swing,jpanel,jbutton
I'm trying to do a program in Java that will make a button appears in a JPanel where and when it's clicked. To do that, I have the method run, with the following code: public void run(){ panel.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e){ JButton button = new JButton(); button.setVisible(true);...

JPanel added to JFrame does nothing

java,swing,graphics,jframe,jpanel
I have the following code: public static void main(String[] args){ Table testtable= new Table(); testtable.setVisible(true); and: public class ChessPanel extends JPanel { @Override public void paintComponent(Graphics g){ // intitlialize background-color super.paintComponent(g); int squareWidth = this.getWidth()/8; int squareHeight = this.getHeight()/8; this.setBackground(Color.WHITE); for(int i = 0; i<8; i++) { for(int j =...

Why doesn't my Jpanel borderlayout work as expected?

java,swing,jpanel,layout-manager,border-layout
I am adding 2 elements to a JPanel, a JLabel and a JButton. I would like them to appear one on top of each other, so I added them using BorderLayout.NORTH and SOUTH. The problem I have is that the JLabel JButton and are sitting next to each other horizontally...

How to store and mark all mouse-clicked-point on an Image loaded in JPanel?

java,event-handling,jframe,jpanel,mouseevent
Up till now I have used the code given below to load image in a new new JFrame and coordinates of pixels of image are hard-coded in the code itself. However, I wish to do it dynamically i.e mark points clicked by mouse and store all the coordinates in an...

How can I change the background color of a jPanel containing JRadioButtons?

java,swing,background,jpanel,jradiobutton
I have an java assignment in which I need to have the background color of a GUI change depending on user selected radio buttons listing different colors. My program has a JFrame to hold everything, then 3 JPanels (1 Instruction area, 1 Radio Button grid, 1 result Textfield) within that...

Java- how to clear graphics from a JPanel

java,swing,jpanel,java-2d
I'm creating a simple program where I draw a black oval where I click with my mouse. However I want a new oval to appear and the old one to disappear. How would I go about doing this? I've messed around with the removeAll() method inserted into my mousePressed method,...

How to move undecorated JFrame by holding click on a JPanel in Java? [duplicate]

java,swing,jframe,jpanel,move
This question already has an answer here: Drag and Resize undecorated JFrame 1 answer I've been making an undecorated JFrame so far and I was wondering if it's possible to move the undecorated JFrame by holding click on a JPanel. Here is the source code I'm working on. private...

Rotate a shape on the same axis in java

java,jpanel,axis,shape,translate
I have this program below. I want the program to rotate the shape on the same spot and also rotate the rectangle more than once. However, the program only rotates the rectangle once and puts the rotated shape on another spot on the frame. I really need help. Thanks!!!!* import...

Update JTextArea text in JFrame from Custom JDialog output data or results

java,swing,jpanel,jtextarea,jdialog
I have a JTextArea inside a main layout that I want to update using a custom JDialog. Difficult to explain in words like this...so please just follow code and explanation process as outlined below: I have a JPanel that contains the JTextArea (i.e. original JTextArea - 'cancellationPolicTA') that needs to...

Stacking JPanels in the same direction

java,swing,jpanel,layout-manager
I would like to stack JPanels on in the same direction. I've searched this and can't find anything. The results that show up mean "overlap". This is what I mean: I would like to stack the second JPanel underneath the first. When using: add(BorderLayout.NORTH) on both layouts it overlaps them....

I added a rectangle to a shape Arraylist but the shape will not show up on the panel

java,arraylist,jframe,jpanel,graphics2d
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.ArrayList; @SuppressWarnings("serial") public class GUI extends JFrame implements ActionListener, MouseListener { private boolean drawLine = false; private boolean drawRec = false; private boolean drawOval = false; private final JButton line; private final JButton oval; private final JButton rectangle; private final JPanel buttonPanel; public...

Java - Applet to Executable Jar Wrapping

java,swing,applet,jframe,jpanel
I have written a Java XML Parser as an Applet. It is looking and functioning well enough in this form. My Question, Is if I want to run this without a browser, how Would I properly wrap it to run as an executable? GUI.java -------------- import java.applet.*; import java.awt.*; import...

Can't get my panel to save as an image

java,swing,jframe,jpanel,bufferedimage
I made a simple paint program but there seem to be some problems. First off, when I run the program, the components don't show up until I drag my mouse over every single one. Secondly, the drawPanel image I create only saves the background of the panel and not the...

How to split JFrame to have console on one side

java,swing,console,jframe,jpanel
I am working on this project github.com/csharpest94/Patience-Game and currently using this as my screen handler: public class Window extends JFrame { private static final long serialVersionUID = 1L; private ThePanel canvas; /** * The constructor creates a Frame ready to display the cards */ public Window() { // Calls the...

3 Jpanel in JFrame, my button is not visible

java,swing,jframe,jpanel
I have a JFrame with three JPanel objects. I have a problem with two of the panels. I can see in my frame, the panel JPanelProduit with object but for the panel, JPanelInformations and JPanelVentes, I see nothing. Where is my error? My Code package IHM; import javax.swing.*; import Donnees.Categories;...

Java - Access datas of a MouseListener from another Component

java,swing,jpanel,mouseevent,mouselistener
I'm currently working on a level editor for a game. Currently, to create an Entity, you have to click on a creation JButton, then a form appears, where you enter its coordinate and its size. I would like to implement a mouse fonction. The user click on the creation JButton,...

Java Game actionPerformed questions

java,jframe,jpanel
Hi everyone so recently i've made a game similar to doodle jump with a jumper/object jumping to the next platform on top and if you fall of you lose. So anyway my game all works but there is one problem, I've make it that if you press on the space...

Why is my Swing app not displaying properly?

java,swing,jpanel,paint
I'm trying to come up with a Swing app that can display all available fonts and show me how they look : import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Demo_Fonts extends JPanel { static String[] font_type; // int[] styles={Font.PLAIN,Font.ITALIC,Font.BOLD,Font.ITALIC+Font.BOLD}; int[] styles={Font.PLAIN}; String[] stylenames={"Plain","Italic","Bold","Bold & Italic"}; Demo_Fonts() { setPreferredSize(new Dimension(500,3000));...

JButton and GUI freezes after click

java,swing,jpanel,jbutton
When Eclipse compiles this code everything works fine except the GUI freezes after the user clicks the "add" button. The answer is displayed and the work is shown. Can anyone shine some light on this problem and maybe give me some advice for the layout as well? import Aritmathic.MathEquation; public...

How to make JOptionPane on top of a Fullscreen Window? [duplicate]

java,window,jpanel,fullscreen,joptionpane
This question already has an answer here: AWT Frame in full-screen exclusive mode gets minimized on windows dialog popup 2 answers I couldn't find any spesific solution for Fullscreen Window so I want to ask. How to make a JOptionPane on the top of a Fullscreen Window? In here...

Updating graphics in JPanel when button is pressed

java,swing,graphics,jpanel
My main class extends JFrame and has a JPanel containing a graphics component, previously I had the following code: public class StartGUI extends JFrame implements ActionListener { public StartGUI { graphArea = new JPanel() { public void paintComponent(Graphics g) { super.paintComponent(g); drawNetwork(myNetwork, this, g); } }; add(graphArea); } However now...

Java JPanel Arc formation around edge of circle

java,jpanel
Im trying to draw an arc that stretches around part of the circle. Im confused on how to use the DrawArc method. I read few articles online and to simply put, im confused on how the parameters exactly work. My circle is centered at 100, 100 with radius of 50....

How to insert JPanel beside a grid?

java,swing,jpanel,layout-manager,grid-layout
I just built this grid using (Java Swing library), and this is the code: import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.*; public class TestGrid02 extends JPanel { private static final long serialVersionUID = 1L; protected static final Color SELECTION_COLOR = Color.red; private JPanel selectedPanel =...

JPanel repaint not working properly

java,swing,jpanel,repaint
I have a JPanel, class is called WorldPanel (look below for code), and I'm using a KeyListener() to move it. It moves, so I don't think it's the KeyListener that is at fault. The problem is that when I call repaint() on the JPanel, it slowly stops repainting a portion...

How to display an image on another image?

java,jframe,jpanel,jlabel,game-engine
I try to create a little game in java but I'm in trouble. When I draw a map, I'm not able to display the characters without overwrite the titlesets of the squares. My goal is to be able to display many pictures on the same square (like the titleset of...

Dynamic width and fixed height of rows in JPanel

java,swing,jpanel,jscrollpane,layout-manager
I am trying to use Java layout managers (I have no external libraries, and am using Java 7) to create a layout where data is provided in rows, where the rows have a fixed height, but the width fills to fit the window. An example is provided below: The idea...

How to change background image of JPanel

java,swing,jpanel
Is it possible to change the Image of a JPanel after it was initialized? Block.java (The JPanel to change img) @SuppressWarnings("serial") public class Block extends JPanel{ private int rotation; public Block(){ } @Override protected void paintComponent(Graphics g){ super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.drawImage(Images.greenBlock, 0, 0, null); } } Now...

Sliding Panels in Java

java,c#,jpanel
+--+-------+-------------+ +-------+-------+--------+ | | | | | | | | | | Zone | | | | Zone | | | | | | -> | | | | | | show | | | | show | | | | | | | | | | +--+-------+-------------+ +-------+-------+--------+...

How To Make A JFrame/JPanel “Modal” So No Input Will Continue Until The Window Is Closed Or Button Pushed?

java,swing,jframe,jpanel
I had another question here and it was suggested me to make the program "modal" in order to block the program from running to the next line and "pausing" the program when a popup happened. I have tried it, but I do not understand how it works 100%. Here's my...

JPanel with triangular border

java,swing,jpanel,border
looking to create a JPanel border like that highlighted in the image in red below.. i.e. triangle at one side or two sides. I've successfully implement rounded JPanel borders using the info here and here. Any ideas or tips? ...

Search Box for Jpanel

java,eclipse,swing,jpanel,windowbuilder
I am in the middle of creating an app that allows users to apply for job positions and upload their CVs. I`m currently stuck on trying to make a search box for the admin to be able to search for Keywords. The app will than look through all the CVs...

How to set a size for a JPanel inside a JFrame?

java,swing,jframe,jpanel
I am trying to put a JPanel in the center of a fullscreen JFrame with a defined size, but it always stretching for all the screen... I tried setBounds, setPreferredSize, but don't works. This is the code: public static void showScene(){ //Create the frame to main application. JFrame frame =...

JPanels will not show up in JFrame

java,swing,jframe,jpanel
I'm making a simple GUI calculator. Before I insert the guts, I'm trying to get the GUI down. The problem that I'm having is that my JPanels containing the keypad and display will not show up in the main JFrame for the program. What am I missing? Main: import javax.swing.*;...

Image did not fresh in Frame on Mouse Click In Java

java,swing,jpanel,mouseclick-event
First Time three random images shown on Jframe from three diffrent arrays. even MouseClicked Method triggered but images does not refresh in Frame. I want to refresh three random images each time i click on Frame. Please help import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Random; import javax.swing.*;...

Getting methods to print to a TextArea in JPanel

java,swing,methods,jpanel,jtextarea
So I am working on a project for a class because I am trying to learn this lovely thing called Java. Well anyway I am trying to get some methods to print out in the TextArea in my JPanel. import java.awt.*; import javax.swing.*; import java.awt.event.*; public class GUI_Amortization_Calculator extends JFrame...

How can I output my data to JPanel from my JFrame

java,swing,jpanel
I have a JFrame named MainGUI. Inside of MainGUI I have passed three LinkedList ll1, ll2, ll3. These LinkedList are full of data and I'm trying to just print one of them on the screen into my JPanel. I'm use to just doing a for loop and using System.out.println to...

How to align JPanel to bottom of JFrame (java swing)

java,swing,jpanel,alignment,layout-manager
Long story short, I'm making a simple audio player in Java and am starting the GUI; no events, no functionality of any kind as of yet. I'm asking how I can the JPanel with the buttons (controls), to align to the bottom center of the main window (JFrame). Here's the...

paintComponent and java Graphics [closed]

java,swing,graphics,jpanel,paintcomponent
I'm still new to java graphics, I wrote this little piece of code, but it doesn't show anything on the screen. can someone please tell me what's wrong. I'm not getting any errors, but it just doesn't show anything. Thanks import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.*; public class...

JPanel revalidate and repaint not working properly (Java Swing)

java,swing,jpanel
I am creating a Sudoku game. The game has some buttons such as new game, re-start, solve, etc. public void inicio() { JPanel panel = new JPanel(); panel.setLayout(null); panel.setPreferredSize(new Dimension(735, 620)); ... button2 = new JButton("New Game"); //Other buttons like this one ... JPanel sudoku = PanelSudoku(); sudoku.setBounds(228, 90, 470,...

Java - Calculating and placing the angle of a geometric shape

java,swing,graphics,geometry,jpanel
I'm currently working on a program which enables user to draw various geometric shapes. However, I got some issues on calculating and placing the angle objects onto my Canvas panel accurately. The angle object is basically an extension of the Arc2D object, which provides a additional method called computeStartAndExtent(). Inside...

JList list items squashed

java,jframe,jpanel,jscrollpane,jlist
I've got my JList working, but only the first list item is its proper size. Everything else under it is squashed. I have searched all StackOverflow and haven't found much (getting it to work was all StackOverflow though) package networks; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.File;...

JFrame Buttons and GridBagConstraints

java,swing,jpanel,gridbaglayout
Why are my constraints for my buttons not working? I looked at the Java Docs and am doing the same thing the tutorials are doing, but for me the buttons stay the same regardless of what gridx, y, width, or fill I use. Any ideas? Here's my code: class MyWindow...

java swing - how to change window background

java,swing,jpanel,jbutton
I was trying to make a button that switches the window background from default to red. I haven't found any preset colors to match the default so i tried to get it from panel.getBackground when i created it. I have an error at line 11, i don't know how to...

Application freezes when I try to draw on a JPanel

java,swing,timer,jpanel,paintcomponent
I have two JPanels: public class FirstPanel extends JPanel public class SecondPanel extends JPanel implements Listener FirstPanel.addListener(SecondPanel) SecondPanel.setPanel(FirstPanel) Listener is an interface that has a single method update(). The SecondPanel has a middleLeftPanel where I want to place the FirstPanel: DesignUtils.addComponentAndConstraints(middleLeftPanel, FirstPanel, DesignUtils.createGridBagConstraint(0, 0, 1, 1, 1, 1, 0, 0,...

GridBagLayout and JFrame Content Pane

java,swing,jpanel,layout-manager
I am currently trying to allign properly some components inside my frame. I am using GridBagLayout for it but it looks like this line is making troubles : frame.setContentPane(new ImagePanel(myImage)); I want to center the buttons in the middle but it doesnt work.If i comment it,everything works good. Also tried...