jpanel

Changing the Panels of a JFrame “disable” the inputMap of the new Panel inserted

给你一囗甜甜゛ 提交于 2019-12-12 12:15:45
问题 Description of the problem: I have a JFrame, inside this JFrame there is a JPanel with a button, when I press the button an action listener change the current JPanel with a new JPanel, which contains other two JPanels, those two have an inputMap that when the user press the key "up" make something on both of them. The problem is: when I change the JPanel with the new one the "up" key won't do anything. Here is the code: is a SSCCE, so you just have to copy and paste to see what it does. This

Multiple JPanels completely on top of each other

懵懂的女人 提交于 2019-12-12 12:12:01
问题 I am creating an program in which I can draw a map and add different roads etc to it. I have planned to add the map terrain on one jpanel, and the roads etc on another, on top of each other. But I can't get them to work. I don't know how to add multiple jpanels completely on top of each other and making them all able to draw. 回答1: The basic approach to this problem would be to use a JLayeredPane and something like GridBagLayout . The JLayeredPane will give you some better control over the z

How To Play MP4 Video In Java Swing App

孤街浪徒 提交于 2019-12-12 12:09:00
问题 Does anyone know any way I can play an .mp4 video file in a JPanel? I have tried JMF with .avi file but found no success and now I'm baffled and frustrated at how such a simple task of playing a video file is becoming so tedious. Anyone out there please shed some light on what path I could take and I would greatly appreciate it. I've heard of VLCJ but the issue is I can't guarantee that every machine running this app will have VLC player installed. Is there a way I can bundle VLC player in

Transparent JPanel over Canvas (VLCJ)

北慕城南 提交于 2019-12-12 12:08:03
问题 I know that a similar question was posted before, but there was no answer or example code. I need a transparent JPanel on top of a canvas. The code posted below is not working import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JLayeredPane; import javax.swing.JPanel; public class Main { private static class Background extends Canvas{ @Override public void paint(Graphics g) { super.paint(g); g

Java scroll JScrollPane with JPanel within to bottom

一世执手 提交于 2019-12-12 11:15:35
问题 I have a JScrollPane with a very high JPanel inside, that is changed dynamically, items being appended at its end. What I want, is to scroll to the bottom of aforementioned JScrollPane in order for the newly appended items to be visible instantly on addition (they are not appended to the scroll pane directly, but to its JPanel, and are private objects, so cannot be referenced. How can I simply have that scroll pane scroll to the very bottom? Thanks in advance! 回答1: JComponent

Java swing keybinding

非 Y 不嫁゛ 提交于 2019-12-12 11:01:19
问题 This is in the constructor of a JPanel but it does not print anything when I press "h". If more code is needed, I can provide it. Thank you! String hide = "hide"; this.getInputMap().put(KeyStroke.getKeyStroke('h'), hide); this.getActionMap().put(hide, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { System.out.println("HIDDEN"); if (isHidden){ slide.setVisible(true); }else{ slide.setVisible(false); } } }); 回答1: this.getInputMap().... You are trying to add the

Java trouble with ArrayLists when there are multiple classes and help fixing up the code [closed]

风格不统一 提交于 2019-12-12 09:56:35
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . I've come to the conclusion that I have 3 questions. How do I use the variables and arrayList of the company class in the Employee class. How should I make the actionListeners so the operate correctly. Would the methods in the Company class work correctly? If not, how should I make them? Check the

Java, BorderLayout.CENTER, getting the width and height of the JPanel

一个人想着一个人 提交于 2019-12-12 09:42:45
问题 I am using Swing and AWT (for the listeners) to make a small program. I have a problem concerning getting the size of my JPanel (the class named Chess). My Layout: public class Main extends JFrame implements MouseListener, ActionListener{ Chess chessPanel = new Chess (); JButton newGameButton = new JButton ("New Game"); JButton loadGameButton = new JButton ("Load Game"); JButton saveGameButton = new JButton ("Save Game"); JButton exitButton = new JButton ("Exit"); public static void main

change JPanel after clicking on a button

喜你入骨 提交于 2019-12-12 09:27:17
问题 I'm building simple GUI for my app. I have couple of JPanels. I want to display them depending on action that was performed by clicking on a JButton. How can I disable one JPanel and enable another one ? Couple of details. I have a class with JFrame where I'm building starting gui. Where I have buttons and some text. Clicking on one of the buttons should change the view in this JFrame my button definition JButton btnStart = new JButton("Start"); btnStart.addActionListener(new ActionListener()

Is there any way to force GridLayout to leave empty cells?

一曲冷凌霜 提交于 2019-12-12 08:34:02
问题 I have a JTabbedPane with 2 JPanels set to GridLayout(13, 11). The first JPanel has enough of the cells filled out that it leaves the empty cells. The second JPanel has significantly fewer cells filled and this results in each button getting stretched to fill an entire row. Is there any way to get GridLayout to honor the empty cells, so the buttons in both JPanels are the same size? 回答1: Use nested layouts to get your desired result. Some layouts respect the preferred size of components and