jframe

How to add buttons and JPanels to a ZOrderComponent?

走远了吗. 提交于 2019-12-25 10:05:09
问题 I'm trying to create a JFrame with a background image, a JLabel over the background image centered and toward the bottom, with two buttons on the right and left that say "Stay" and "Leave". This is already created. The issue arises with the order of each of the items. I cannot get the JLabel with text and buttons over the background image, with both of them showing. Here is my code; any advice would be appreciated. Thank you in advance. public class SceneOne { public static void main(String[]

Mac: Full Screen JFrame losing keybindings from mouseadapter

[亡魂溺海] 提交于 2019-12-25 09:35:17
问题 On my Mac, fullscreen JFrames initially have key bindings that do not work, and the computer outputs alert beeps each time I try to type. There is a workaround, though, after fully initializing my JFrame, I added these lines of code and all the errors stopped: setVisible(false); setVisible(true); Here's the source of this workaround: http://mail.openjdk.java.net/pipermail/macosx-port-dev/2012-November/005109.html Another problem which is yet to be solved is adding a mouse adapter to my full

Why can't I erase my Sprite

那年仲夏 提交于 2019-12-25 09:26:17
问题 I've been trying for a while now to get a game working in Java, after much anguish over other peoples Sprite functions I made my own and don't understand why I can't erase it. I know it's changing the pixels of the background to display my archer sprite since it shows up but for whatever reason I can't change the pixels back to what they were before. Does anyone have an idea why that is or how I can fix it? Link to google doc with images: https://docs.google.com/document/d/1eU6faW1d7valq1yE

Java - Prevent Resize but keep adding text to JTextArea with JScrollPane

被刻印的时光 ゝ 提交于 2019-12-25 08:57:56
问题 I have made a JTextArea in which I log some info(With an endless loop) I have already set the Preferred Size and added it to a JScrollPane . After logging messages reach the limit of the Jtextarea they stop printing on the screen . I want then to keep printing (and the scrollbar getting smaller and smaller), pretty much like a CMD prompt does. This is necessary because I already have another Jtextfield below and a button 回答1: Don’t set a preferred size on the JTextArea . Set the preferred

To have a JFrame without adjusting for taskbar change

妖精的绣舞 提交于 2019-12-25 08:48:17
问题 I need to have a JFrame, which when i change the window taskbar size or position, the frame shouldn't adjust itself. Which method of the JFrame will be called exactly on changing the taskbar size and position? Which method will I be required to override? To put it in more clear words, By default the instance of JFrame will adjust its height and width by itself when I change the size and position of the window taskbar. But my JFrame shouldn't respond when I extend the window taskbar or when I

Trouble Drawing In JPanel

本小妞迷上赌 提交于 2019-12-25 07:35:19
问题 I'm going to start off by saying that I can almost guarantee that this question is going to be a copy but I couldn't find any other answers that suited my needs / worked on my program. I need to draw on a JPanel , but I can't seem to be able to get the line I need to draw to show up. JFrame drawF = new JFrame("Simulator"); JPanel simPanel = new JPanel(); drawF.setVisible(true); drawF.setSize(1000,650); drawF.add(simPanel); drawF.pack(); simPanel.setLayout(null); simPanel.setSize(1000,650);

SetBounds not working properly

坚强是说给别人听的谎言 提交于 2019-12-25 07:07:08
问题 I want to make 3 panels, where one is to the west side, one to the east, and one to the south. When I complie this, it gives me frame with colors all one above another and it doesn't give me buttons. frame = new JFrame(); frame.setBounds(600, 200, 500, 350); frame.setTitle("Dr. Idrizovic"); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panelWest = new JPanel(); panelWest.setBounds(0, 0, 175, 310); panelWest.setLayout(null); panelWest.setBackground(Color.green);

How the pack() function behave when we explicitly set the location of the container?

帅比萌擦擦* 提交于 2019-12-25 06:38:39
问题 Here is the minimal example what problem I am facing in my main GUI design import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.BoxLayout; class GuiTester { JFrame mainFrame = new JFrame(); JPanel panel = new JPanel(); GuiTester() { JButton newButton = new JButton(); JButton continueButton = new JButton(); panel.setLayout(new BoxLayout( panel, BoxLayout.Y_AXIS)); panel.add(newButton); panel.add(continueButton); panel.add(new JButton()); panel

adding multiple buttons using JPanels

蹲街弑〆低调 提交于 2019-12-25 06:32:05
问题 I have created a simple compass program that moves the GUI box around the screen and I am now progressing on to adding NE, NW etc. This involves using JPanels as this allows multiple objects. My issue is that I've made 9 separate panels for the separate buttons but I have no idea how to add them to the JFrame as everything I do doesn't seem to work. Any ideas would be appreciated. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MovingCompassExtraJFrame extends

onclick i want to get the name of the JPanel that is present on the JFrame

别说谁变了你拦得住时间么 提交于 2019-12-25 05:54:54
问题 Below is what im trying to implement but its giving error on the line mentioned ; this is because the function doesnot get which Component.getName() is of ... String name=new String(); mntmOneToOne.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { String name=new String(); int count = arg0.getClickCount(); if (count == 1) { Component panel = (Component) arg0.getSource(); System.out.println(panel.getName()); } } }); 回答1: Get the clicked object via your