jframe

BorderLayout - child component remains visible after adding another component

 ̄綄美尐妖づ 提交于 2020-01-15 15:31:58
问题 I try to do the following thing: Add a component to a JFrame with a BorderLayout Add another component to the JFrame I would expect the new component to 'overwrite' the old component, since I'm using a BorderLayout . This works if I overwrite the old component before I call pack() . Now if I add the 2nd component after I call pack() , both components remain visible. Example: public class Test extends JFrame{ public Test(){ setLayout(new BorderLayout()); add(new JLabel("Quite a long text"));

How do I lock the mouse inside a JFrame

淺唱寂寞╮ 提交于 2020-01-15 12:25:51
问题 I would like to lock the mouse inside a JFrame. That is, the mouse can not leave the contents of the JFrame (unless the user hits escape, alt-tab, or the window otherwise looses focus). Ideas? Thanks! 回答1: I'm not sure if there's a more automatic way of doing that, but you could use the Robot class to set the mouse position. So in the event handler for when the JFrame gains focus you can start watching the mouse move event, and when the mouse moves just make sure it stays within the JFrame.

Is there a way to animate an entire Jframe in Java so that it moves?

自古美人都是妖i 提交于 2020-01-15 12:12:25
问题 I would like to create a program where the Jframe is able to move freely on it's own. Kind of like a translation / transition. For example, Click on program to begin. Jframe spawns at location (0,0). Automatically move (animate) 100 pixels to the right so that the new coordinates are (100,0). I know there's the setLocation(x,y) method that sets the initial position once the program runs but is there a way to move the entire Jframe after the program starts? 回答1: The basic concept would look

Placing JFrames inside JFrames

狂风中的少年 提交于 2020-01-15 11:59:41
问题 I'm working on an application that contains many JFrames, with the amateurish result that my program appears in the taskbar many times, one for each currently visible JFrame. I'm aware that JInternalFrame might solve my problem, but I've already made so many JFrames it's hard to switch! Is it possible to make my already-made JFrames appear within an overarching JFrame? Perhaps to somehow "transfer" each JFrame into a JInternalFrame? What I ultimately want my application to look like is

Using multiple classes with the same JFrame

泪湿孤枕 提交于 2020-01-15 11:37:11
问题 I've been in a bit of a pickle here. I've been ripping my hair out over how to accomplish such a task. For my International Bacc I have to fill out certain criteria for my Program dossier and one of them is using inheritance and passing parameters etc. I'm in the stage of making my prototype and wanted to achieve the effect of using multiple JPanels within the same JFrame. I've achieved this rather crudely with setVisivble() and adding both panels to the JFrame. I understand that I can use

How to know if a JFrame is on screen in a multi screen environment

▼魔方 西西 提交于 2020-01-15 08:39:08
问题 My application is used in multi-screen environments. The application stores it's location on close and starts on the last position. I obtain the position by calling frame.getLocation() This gives me a positive value if the frame is on the main screen or it is on the right of the main screen. Frames located on a screen left to the main screen get negative values for X. The problem comes up, when the screen configuration changes (for example multiple users share one Citrix-Account and have

JButton with both ActionListener / MouseListener

蹲街弑〆低调 提交于 2020-01-15 07:18:30
问题 Is it possible to create a Jbutton with both an ActionListener and MouseListener Meaning so i create a button and then when i press it ( throught actionListener) it changes the frame so that AFTER then button was pressed i can press anywhere on the frame and MouseListener would in use. JButton button = new JButton();//Creates Button button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //Insert MouseListener //Then do something with mouseListener } });

Can any one help Printing a JFrame with all its component in Java program

爷,独闯天下 提交于 2020-01-15 02:55:59
问题 Hello everyone, Now a days i am facing a serious problem. I have made a java program and one of the JFrame of this program needs to be printed. But i can't do that. I have searched on the web but the code i have found only prints the first element means just 1 element may be JLabel or JTextBox. But i need to print the whole page with all data. Can anyone please help me? Thanks 回答1: Attach this code to your class. Hope this will help you First of all implement the Printable interface to your

Window Size is smaller than it should be

大城市里の小女人 提交于 2020-01-14 19:42:31
问题 Alright so I've got this JFrame with a screen on it. I've set the size to 800 by 800. However the window is created smaller than that. It's not a problem with the taskbar because it's not fullsize. package sharph; import java.awt.Dimension; import javax.swing.JFrame; public class Main extends JFrame { public static String Title = "Game 1"; public static Dimension screenSize = new Dimension(800,800); public static void main(String[] args) { JFrame frame = new JFrame(); frame.setTitle(Title);

Paint in JFrame not working (Java)

爷,独闯天下 提交于 2020-01-14 10:42:10
问题 So in class we are making a Java program. We are trying to use the paint(Graphics g) function in the JFrame. We have tried it in the past (weeks ago) and it used to work. But now it doesnt (or we made a mistake somewhere). We have also tried to use paintComponent(Graphics g) but nothing seems to work. Here is our code: public class MainAc { public static void main(String[] args) { JFrame frame = new JFrame("Class Paint"); JButton button = new JButton("Click for more"); frame.setSize(800, 600)