jpanel

What's so special about CardLayout vs manual adding/removal of JPanels?

空扰寡人 提交于 2019-11-27 02:13:00
问题 There have been many times on StackOverflow where a user asks a question like this... I have a main JPanel that contains a child JPanel . When the user clicks a button, the child JPanel should change to a different JPanel . How can I achieve this. More often than not, the user has actually tried to implement this problem, but can't get it working. Whenever I answer this question, I tell them to do something like this (put simply)... JPanel myFrame = new JPanel(); myFrame.remove(oldPanel);

adding multiple jPanels to jFrame

时光毁灭记忆、已成空白 提交于 2019-11-27 01:57:04
问题 I want to add two jPanels to a JFrame side by side. the two boxes are jpanels and the outer box is a jframe I have these lines of code. I have one class called seatinPanel that extends JPanel and inside this class I have a constructor and one method called utilityButtons that return a JPanel object. I want the utilityButtons JPanel to be on the right side. the code I have here only displays the utillityButtons JPanel when it runs. public guiCreator() { setTitle("Passenger Seats"); //setSize

How to add JPanel by clicking JButton?

六眼飞鱼酱① 提交于 2019-11-27 01:48:05
I'm trying to create a small GUI, it has 2 JButtons, and 2 JPanels with some drawing animation on each of them. By default it must show first JPanel, and by clicking on second JButton I want to see my second JPanel. So : I create JFrame, Panel1 and Panel2, where I have drawn my animations, create Button1 and Button2 and adding to them ActionListeners. I have also MainPanel which has in a fields variable i. By changing this "i" my constructor adds to MainPanel either Panel1 (default) or Panel2 (by clicking on JButton2 I change i). Than I add this MainPanel to my frame. So my question : in the

Java - Vertical “FlowLayout” with Horizontal Scrolling

那年仲夏 提交于 2019-11-27 01:36:29
问题 As described in the title, I've been trying to set up sort of a vertical flow layout with horizontal scrolling. The components within the layout will be JLabels. Let me draw a picture: +-------------------------+ <--- window |Label1 Label4 Label7| |Label2 Label5 Label8| <--- labels |Label3 Label6 Label9| |<===============>========| <--- scrollbar +-------------------------+ Same window, expanded vertically +--------------------------+ <--- window |Label1 Label5 Label9 | |Label2 Label6 Label10

Make an added JPanel visible inside a parent JPanel

梦想与她 提交于 2019-11-26 23:31:30
问题 How to make an added JPanel visible inside a parent JPanel ? I am using Netbeans for designing my UI. I have a MainFrame.java , which contains two panels; namely headerPanel and bodyPanel . In headerPanel I have put three buttons,let it be button1 , button2 and button3 . Also I have created three separate files extending JPanel , name it panel1 , panel2 and panel3 . Then I added all my three panels inside bodypanel in MainFrame.java in constructor. bodyPanel.add(panel1); bodyPanel.add(panel2)

Embedding VLCJ in JPanel

北慕城南 提交于 2019-11-26 23:29:31
问题 I have read this SO thread and when I have tried to use the code with some changes, I'm getting just a black window, can some one tell me what I'm doing wrong here, I have just one class with main function : import java.awt.Color; import javax.swing.JFrame; import javax.swing.JPanel; import com.sun.jna.NativeLibrary; import uk.co.caprica.vlcj.player.MediaPlayerFactory; import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer; import uk.co.caprica.vlcj.player.embedded.videosurface

Zoom box for area around mouse location on screen [closed]

痞子三分冷 提交于 2019-11-26 23:13:26
Is there any way to create a dynamic Zoom Box in Java which will include e. g. 20x20pix area around the cursor (but even when cursor will move beyond the Frame of app) and which will be shown for example in a small JPanel? I'm asking in context of a Color Chooser program. The last functionality need to be implemented is just that Zoom Box. I'm sure there are a number of different ways that this could be achieved. This basically uses a separate component, which acts as the "zoom box". You supply it a component that you want to "zoom" on. It adds a mouse listener so it can monitor mouse motion

Convert a JPanel to an image in a JScrollPane

廉价感情. 提交于 2019-11-26 23:11:32
问题 I want to convert an JPanel to an image. I used the following method: public BufferedImage createImage(){ int w = getWidth(); int h = getHeight(); BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); paint(g); return bi; } But the problem is that the JPanel is contained within a JScrollPane. So when I convert the jpanel to an image, the image contains only the parts visible in the jpanel and the parts that are hidden inside the scrollpane

Background image for a jPanel not working

ⅰ亾dé卋堺 提交于 2019-11-26 23:08:07
I am new to making GUIs so I decided to try the the windows builder for eclipse, and while great I do have some doubts. I have been searching but I cannot seen to find a good way to add a background image to my "menu". For example I tried this: public Menu() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(50, 50, 300, 250); //Dimensiones contentPane = new JPanel() { //Imagen de Fondo public void paintComponent(Graphics g) { Image img = Toolkit.getDefaultToolkit().getImage( Menu.class.getResource("/imgs/rotom.jpg")); g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this); }

Java Linux Terminal in JPanel

大城市里の小女人 提交于 2019-11-26 23:02:55
I am making a Scripting Editor and would like to be able to run the Bash/Shell/Python/etc. scripts in the program... So far, I have a way of running them, but there is no way for the scripts to have user input; here's the code: package com.hightide.ui.terminal; import javax.swing.*; import java.awt.*; import java.io.BufferedReader; import java.io.File; import java.io.InputStreamReader; /** * Created by peter on 9/1/15. */ public class JTerminal extends JPanel { private final JTextArea jta; public JTerminal(){ super(); setLayout(new BorderLayout()); jta = new JTextArea("-- HIGH TIDE SCRIPTING