jpanel

Repaint does not update the screen

不打扰是莪最后的温柔 提交于 2019-12-02 12:11:22
I would like to repaint my screen. As of now all it does is show the first screen with a dot where the head is supposed to be. This is fine, however I've written in my code that I want to move the head down 10 pixels every second. I'm printing at what point the head is supposed to be at, and in the command prompt it shows that the y value is indeed increasing. However on my screen the head is not moving. I have tried using the revalidate method, trying to extend the canvas class instead of jframe, I have tried using different classes just for the paint method, i have tried replacing the paint

How do I make my button display at the time I want it to?

邮差的信 提交于 2019-12-02 12:09:23
I'm working on this game for my girlfriend and I've been stuck on the same problem for a few days now. Basically, I want her to be able to press the "Gather Wood" button 5 times then, right after she presses it the fifth time, the "Create Fire" button should pop up. 1.The problem is that no matter which way I attempt to program the method to show up on the fifth button press it just doesn't show up. I would appreciate any coding tips or anything y'all think I can do to clean up my current code. private static JPanel panel; private static int woodCounter; private static int leafCounter; private

Simple JFrame program but can't see JTextfield

≡放荡痞女 提交于 2019-12-02 11:50:26
I'm trying to learn Swing on my own. I'm playing with a toy program that asks the user to input their name. I put a JLabel and JTextfield into a JPanel where the user can input their name and submit. However my JTextfield is squished up and invisible and I can't get it to show (I've tried "setSize" to no avail). This is my code: import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class NamePrompt extends JFrame{ private static final long serialVersionUID = 1L; String name; public NamePrompt(){ setLayout(new BorderLayout());

Add Object to JPanel after button click

扶醉桌前 提交于 2019-12-02 11:34:09
问题 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 unchangeable sizes. I would like it if the added objects had different sizes - adjusted to the text content. What should I use for it and how? Thanks in advance. Best regards,

Not able to add 3 JPanels to a main panel

折月煮酒 提交于 2019-12-02 11:32:50
问题 I have 3 JPanels and I want to place them all in one JPanel. I used the GridBagLayout for the main panel. But only one panel is getting added. Why might this be? gblayout=new GridBagLayout(); gbc=new GridBagConstraints(); panel1Customizer(); panel2customizer(); panel3Customizer(); setLayout(gblayout); gbc.fill=GridBagConstraints.HORIZONTAL; gbc.anchor=GridBagConstraints.NORTHWEST; gbc.weightx=1; gbc.weighty=1; gbc.gridheight=GridBagConstraints.REMAINDER; add(panel1, gbc); add(panel2, gbc);

swing layout - center panel to scroll with multiple JEditorPanes

陌路散爱 提交于 2019-12-02 11:06:27
问题 Im having trouble getting Swing layouts to do what I want. I want the Center panel which contains two JEditorPanes to scroll when it contains 'n' Panes of equal (fixed) height. I've been playing around in Netbean's UI designer to try to get it to work jPanel3 is the center panel jEditorPane4 and 5 are some example editor panes (these will hold comments) public class GBugForm1 extends javax.swing.JFrame { public static void main(String[] args) { GBugForm1 form; form = new GBugForm1(); form

How to add scrollbar to panel?

寵の児 提交于 2019-12-02 10:53:53
I need help. I have one panel which can need to have width 1000px. I need to add lot of buttons with different size ( I add with flow layout and it works fine). Problem is that I have height on screen example 500px but when I add buttons panel has bigger size. How to add scrollbar to panel ? Add your panel to scrollpane and add that pane where you are adding your panel instead of panel JScrollPane jScrollPane = new JScrollPane(panel); 来源: https://stackoverflow.com/questions/5790525/how-to-add-scrollbar-to-panel

Add components directly to JFrame, or put them inside a JPanel?

依然范特西╮ 提交于 2019-12-02 10:36:33
问题 I have a general question regarding java GUI. If I have several components that I want to add to a JFrame, should i put them directly inside the JFrame, or add them to a JPanel, and then add the panel to the frame? If adding the components to a JPanel first is the best, why? I usually do this, then I understood that I have no idea why/if this is more optional then adding directly to the frame. JFrame also have layout managers, so it's possible to get them in the correct position. 回答1: When

Java Painting not working

陌路散爱 提交于 2019-12-02 10:24:27
So I have this code: package tictactoe; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JFrame; import javax.swing.JPanel; public class TicTacToe extends JFrame { public static void main(String[] args) { JFrame masterFrame = new JFrame("TicTacToe"); JPanel drawingPanel = new JPanel(); GameBoard theGame = new GameBoard(); masterFrame.add(drawingPanel); masterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); masterFrame.setSize(504, 504); masterFrame.setResizable(false); masterFrame.setLocationRelativeTo(null); masterFrame.setVisible(true); } //End of Main method

BorderLayout only showing one object

ぃ、小莉子 提交于 2019-12-02 10:19:05
I decided to write a small Java program to experiment around with BorderLayout, because I'm developing a Java game and I need to have 2 objects placed in a single JFrame at the same time, and everyone I asked said I need BorderLayout to do that. So the Java program I wrote is supposed to place a JButton on the JFrame and ALSO place a graphic component (a rectangle in this case). The problem is, only the button shows up, as can be seen in the image link below: http://prntscr.com/3m5ek6 I can't post actual images due to my low reputation statistic. Here is the code: main.java --> The main method