jpanel

Java GridBagLayout and JPanel Error: cannot add to layout: constraint must be a string (or null) [duplicate]

断了今生、忘了曾经 提交于 2019-12-13 06:27:06
问题 This question already has an answer here : getting Exception : java.lang.IllegalArgumentException: cannot add to layout: constraint must be a string (or null) (1 answer) Closed 6 years ago . I have researched this error and I cannot seem to find a solution. I am trying to create a grid of 800 JButtons with 40 columns and 20 rows. This will eventually be used to control a domino setting up robot I am making that will tip over dominoes. I have already successfully created a grid using

How To Access Controls On a JPanel…?

元气小坏坏 提交于 2019-12-13 05:40:17
问题 I'm a Java n0ob....so let me apologize in advance... I've got a jPanel that I've added a bunch of controls to, dynamically, at run-time. Later, in my code, I want to loop through all of those controls (they are jCheckBoxes) to see if they are checked or not. In .NET - I'd be looking at some like... For Each myControl as Control In myPanel.Controls Next Is there a way to accomplish that with the jPanel? Should I not be using a jPanel for this? 回答1: Here is a method I wrote to set the font for

Java panel/frame graphic not working

末鹿安然 提交于 2019-12-13 05:13:37
问题 I am trying to make a game of life simulation using Java Graphics but when a run my code the left one third of the screen is grey.I want the whole screen to be white with black squares representing living squares. I am confused about all the java containers/panels and frames. Here's my code: public class ConwayGame { static JPanel panel; static JFrame frame; public static void main(String[] args) throws InterruptedException{ int [][] array = new int [40][40]; /* * Set the pattern for Conway's

JPanel Smaller than JFrame

梦想的初衷 提交于 2019-12-13 05:12:57
问题 I never actually create a JPanel , but I seem to be having issues with it inside of my JFrame . my "fball" object goes off the screen at random parts and I cannot figure out why for the life of me. I don't actually create a JPanel and use the methods to set it up, and dont know how to do that since my class that extends JPanel only creates an image. If you help me I will love you forever. (I apologize for my lacking of knowledge in java) Here is the code for my Window Class: package game

What is the most efficient way to implement particle filters in Java?

旧街凉风 提交于 2019-12-13 05:04:38
问题 I am working on implementing a particle filter localization in Java, in which I have to create a GUI and then fill it with 100 particles and a robot. Then, i have to update the particles and robot periodically. For example, I will increment the values of x and y by 5 units every time. What should be the design of such a project? I am having a method createGUI and I am calling the constructor to create and fill the particles in the frame. But how will I update the points again and again. Will

How to get location of textarea in JPanel

半城伤御伤魂 提交于 2019-12-13 04:55:09
问题 I have created a JFrame containing 2 JPanels(panel1,panel2) .i have added panel2 in panel1. panel1.add(panel2); i have added a text area into panel2. panel2.add(textarea); finally panel1 to getContentPane getContentPane().add(panel1); now i am getting the location of textarea by textarea.getLocation(); i have created a Save button which saves the textarea(x,y) values.i am using xml to store (x,y) values. now when i close and reopen the jar file the textarea place is not changed but the xml

Replace JTextField with an Image?

泪湿孤枕 提交于 2019-12-13 04:53:28
问题 I've been searching on way's to replace a JTextField with an Image & nothing comes up. Is it possible to add a jtextfield onto an image or replace on with an image? I'm using a JPanel & I am trying to put the JtextField inside the image below: 回答1: There are several ways this might be achieved... The simplest might be to use a JLabel , set it's layout manager to something BorderLayout and simply add the text field to it... JTextField field = new JTextField(); field.setOpaque(false); JLabel

Add dynamic buttons to jpanel in Java

坚强是说给别人听的谎言 提交于 2019-12-13 04:52:29
问题 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); button.setAlignmentX(e.getXOnScreen()); button.setAlignmentY(e.getYOnScreen()); panel.add(button); panel.revalidate(); panel.repaint(); } }); } The problem is, nevermind

How to paint over a JPanel?

和自甴很熟 提交于 2019-12-13 04:47:25
问题 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 to paint the oval. I tried repaint instead but nothing happened. Any help would be appreciated. Here is my main class: public class Checkers extends JPanel{ public static final int BOARDSQUARES = 8; public static final int BOARDSIZE =

Java - Sprite in JPanel error

时光毁灭记忆、已成空白 提交于 2019-12-13 04:44:39
问题 Every time i run the panel is filled with a white line in the corner of it and the rest is black. I would like to add KeyListener to the program so when i push the "W" key it will animate the sprite as it seems to be going forward. IF the sprite is not centered all the time than how would i code a collision detect to repaint the map when the sprite image block reaches the edge of the panel. I know im asking more than one question yet im tring to figure out one problem. How would i spawn a