jpanel

Two JPanels in JFrame , One under other

依然范特西╮ 提交于 2020-01-03 18:59:53
问题 I've got two panels in my frame, and I would like to set them one under other, and this first should have size like 9/10*screen frame, and this second 1/10. I've tried with GridLayout (2 rows and one column) but I can't set them specific size. How should I do that? ok maybe I will write some my code: I am writing game - pacman, and in the first panel there is a whole game, and in this second I would like to display player info(like score, name etc.) This first I would like to set on 80%

getWidth() and getHeight() are 0 after calling setPreferredSize()

◇◆丶佛笑我妖孽 提交于 2020-01-03 17:11:11
问题 I've been working on my project for a few hours now, only to be constantly frustrated at this. I have a parent JFrame that adds a JPanel to it, and it is going to be used for the rendering and display of my simulation I'm developing. There are no swing objects that are going to be added to the JPanel, as I will only be using it for rendering shapes using a graphics object. My code is as such below: public class SimulationPanel extends JPanel { private BufferedImage junction; private

getWidth() and getHeight() are 0 after calling setPreferredSize()

余生长醉 提交于 2020-01-03 17:09:12
问题 I've been working on my project for a few hours now, only to be constantly frustrated at this. I have a parent JFrame that adds a JPanel to it, and it is going to be used for the rendering and display of my simulation I'm developing. There are no swing objects that are going to be added to the JPanel, as I will only be using it for rendering shapes using a graphics object. My code is as such below: public class SimulationPanel extends JPanel { private BufferedImage junction; private

Java- how to clear graphics from a JPanel

主宰稳场 提交于 2020-01-03 13:36:13
问题 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, however it isn't working for me. Is the removeAll() method even suitable for this? Or should I use something else? Sorry if the answer is obvious, but I am still new to this and trying to learn. Any advice would be immensely

Calling swing JPanels from actionlistener

孤街醉人 提交于 2020-01-03 04:54:11
问题 im coding a project using various classes, but i got stuck when i press a button which call my main menu, here's my resumed code: My main class: public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { Dimension res = Toolkit.getDefaultToolkit().getScreenSize(); public void run(){ Principal frame = new Principal("Program"); frame.setSize(res.width,res.height); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setUndecorated(true

How to layout? (JFrame, JPanel, etc.)

折月煮酒 提交于 2020-01-03 03:06:11
问题 I'm very new to Java Swing and Java overall (my class just got finished on Scanner and basics). I was taught only Swing basics which is "What is a JFrame..etc" and I'm stuck on how to layout or position things. On the image is the layout I desired and could anyone help and teach me how to code it? JFrame with, 5 JPanel components?(4 columns and the order form below) Additionally, when clicking the "CONFIRM" button, I would want a new window to popup. How would I be able to link multiple

How to centre the Buttons in my JFrame?

被刻印的时光 ゝ 提交于 2020-01-03 02:26:08
问题 I am trying to make a board game, I have Player 1 label and player 2 label set to the east and west. I am having trouble centre my 3 x 10 buttons. And is there any simpler way of making all 30 buttons at once? Below is my Code: JPanel panel = new JPanel(); JButton button1 = new JButton();JButton button2 = new JButton(); JButton button3 = new JButton();JButton button4 = new JButton(); JButton button5 = new JButton();JButton button6 = new JButton(); JButton button7 = new JButton();JButton

Why I cannot add a JPanel to JFrame?

女生的网名这么多〃 提交于 2020-01-02 13:33:32
问题 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; } // Start the window in the EDT. public void start() { SwingUtilities.invokeLater(new Runnable() { public void run() { showWindow(); controller.start(); } }); } //

How to auto scroll to bottom in Java Swing

感情迁移 提交于 2020-01-02 04:52:14
问题 I have a simple JPanel with a JScrollPane (with vertical scrollbar as needed) on it. Things get added to (or removed from) the JPanel and when it goes beyond the bottom of the panel, I want the JScrollPane to scroll down to the bottom automatically as needed or scroll up if some components go away from the panel. How shall I do this? I am guessing I need some kind of listener which gets called whenever the JPanel height changes? Or is there something as simple as JScrollPanel.setAutoScroll

How to put a JButton at a specific location?

安稳与你 提交于 2019-12-31 07:20:29
问题 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 = null; public DetectMotionExample() { JPanel pnlButton = new JPanel(); label = new JLabel(nothing); JButton btn = new JButton("Close"); pnlButton.setLayout(new BorderLayout()); setTitle("Motion Detector");