jframe

More than one JPanel in a Frame / having a brackground Image and another Layer with Components on the top

馋奶兔 提交于 2019-11-29 15:22:58
I've got a JFrame with a JPanel in which there is a JLabel with an ImageIcon(). Everything's working perfectly, problem is i now want to add another JPanel with all the other stuff like buttons and so on to the JFrame. But it still shows the background Image on top and nothing with the second JPanel. Can someone help me? Here is an extract of my code: JFrame window = new JFrame("Http Download"); /* * Background Section */ JPanel panel1 = new JPanel(); JLabel lbl1 = new JLabel(); /* * Component Section */ JPanel panel2 = new JPanel(); JLabel lbl2 = new JLabel(); /* * Dimension Section */

How to set an icon to a JFrame when using createAndShowGUI() method?

北城余情 提交于 2019-11-29 15:12:47
I am using a createAndShowGUI() method to create a JFrame . I am trying to set an icon, but when I run it in NetBeans, it doesn't show. However, when I run a .jar file (with the image in the same folder), then it works without a flaw. private static void createAndShowGUI() { //Create and set up the window. JFrame game = new JFrame(); game.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); game.setSize(198, 409); game.setResizable(false); game.setTitle("Frame Title"); ImageIcon img = new ImageIcon("Icon.png"); game.setIconImage(img.getImage()); game.setVisible(true); } Any ideas where the problem

Adding JPanel from another class to JPanel in JFrame

你说的曾经没有我的故事 提交于 2019-11-29 14:18:38
问题 I can't get my JFrame from main class to display JPanel from another class. Everything compiles without errors. JFrameTest.java: package jframetest; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class JFrameTest extends JFrame { public JFrameTest() { FlowLayout mainLayout = new FlowLayout(); setSize(320, 480); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(mainLayout); JPanel panelMain = new

MouseListener on JFrame

倾然丶 夕夏残阳落幕 提交于 2019-11-29 14:16:56
I want to be notified of mouse events (specifically the mouse entered and exited events) on my JFrame. But when i add a mouselistener to it i get the events on the borders of the frame not the entire frame with it's contents. Any ideas as to why? EDIT : Or at least do you have an alternative? I want a "gloabal" way to catch mouse events on the JFrame. Maybe a mouselistener is not the answer. You can get all events and check if their source is a component in the JFrame. See Toolkit.addAWTEventListener There is an invisible component that overlays the whole GUI, the "glass pane". You can attach

JFrame isResizable(false) sizing issue

三世轮回 提交于 2019-11-29 14:12:05
I intended to make a JFrame with a ContentPanel of 600x600 and I wanted the JFrame to be not re-sizable. Inside this box, I Drew a 600x600 red-outlined rectangle to make sure that everything matched when i ran the program. Before restricting resizing for the JFrame, I set the size of my JFrame by doing: getContentPane().setPreferredSize( new Dimension(600,600)); pack(); And when I launched the program and the boundaries of my rectangle fit perfectly with the dimensions of the JFrame. However, when i added isResizable(false) into the equation, there seemed to be buffer of pixels between the

How do you make key binding for a JFrame no matter what JComponent is in focus?

白昼怎懂夜的黑 提交于 2019-11-29 14:00:42
How do we make key bindings for a JFrame regardless of what's in focus in the frame? I already looked at this question: How do you make key bindings for a java.awt.Frame? I tried setting the input map for the root pane of the JFrame, but it doesn't work when the focus is on a JTextArea even though editable is false. What's the easiest way to make key bindings work across an entire JFrame? I tried setting the input map for the root pane of the JFrame, but it doesn't work when the focus is on a JTextArea even though editable is false. Correct. If a component has focus and implements the same

Java GUI, Multiple Frames

这一生的挚爱 提交于 2019-11-29 12:58:34
How do I go about creating what I describe below? First, here is the basic look of my GUI: When I click on Add New Account I want to have the GUI pop up a small window where the user can enter log-in credentials. I would need this information to be passed back into the main GUI, so I am lost as how to approach this. The same goes for Preferences or Remove Account . How do I go about creating a "GUI Overlay" of sorts. Sorry, I can't figure out the correct terminology for the effect I am looking for. I wanted to attempt to use JOptionPane 's, but after some research this seemed like it was not

How to make a button that, when clicked, opens the %appdata% directory?

佐手、 提交于 2019-11-29 12:44:37
I have made a button, but I don't now how to make it open a specific directory like %appdata% when the button is clicked on. Here is the code -> //---- button4 ---- button4.setText("Texture Packs"); button4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileChooser=new JFileChooser("%appdata%"); int status = fileChooser.showOpenDialog(this); fileChooser.setMultiSelectionEnabled(false); if(status == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); // do something on the selected file. } } And I want to make something

Making a JPanel manually resizable

↘锁芯ラ 提交于 2019-11-29 12:24:41
问题 I have a JFrame with BorderLayout as the layout manager. In the south border, I have a JPanel , I want this JPanel 's size to be adjustable by the user, i.e. the user can click on the edge of the border and drag it up to make it larger. Is there any way you know that I can do this? 回答1: In order to make panels in a frame individually resizable you need to add them onto a JSplitPane. Instead of putting it in the South portion of the Frame, put the JSplitPane in the Center. The split pane will

How to change the dimension of a component in a JFrame

陌路散爱 提交于 2019-11-29 11:57:14
Suppose I have a JPanel in a JFrame. When I invoke a method that changes the preferred size of that JPanel, it does not change. The code looks something like this: public class SomePanel extends JPanel{ public SomePanel(){ setPreferredSize( new Dimension( 390, 40 ) ); setBackground( Color.BLACK ); } public void expand(){ setPreferredSize( new Dimension( 390, 200 ) ); } public static void main( String args[] ){ JFrame frame = new JFrame(); frame.setSize( 450, 500 ); frame.setLayout( new FlowLayout() ); SomePanel somePanel = new SomePanel(); frame.add( somePanel ); frame.setVisible( true );