jpanel

How to add JPanel by clicking JButton?

别来无恙 提交于 2019-11-26 09:49:37
问题 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

Java Linux Terminal in JPanel

别来无恙 提交于 2019-11-26 09:14:03
问题 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;

Background image for a jPanel not working

♀尐吖头ヾ 提交于 2019-11-26 09:13:59
问题 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

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

左心房为你撑大大i 提交于 2019-11-26 08:37:01
问题 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. 回答1: 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".

Concerns about the function of JPanel: paintcomponent()

不羁的心 提交于 2019-11-26 08:13:42
问题 hello I\'m new in java programming, and i need someone explaining me these lines of code: public class drawpanel extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); ... } } I dont understand the line public void paintComponent(Graphics g) : why do i have to declare that function like that if it\'s predefined in JPanel? And this line super.paintComponent(g) : I dont understand it at all. Thank you for your help. 回答1: The Basic Structure: The extends keyword means

Why is my JLabel not showing up

核能气质少年 提交于 2019-11-26 06:08:57
问题 I am calling this method called check in one of my abstract classes but for some reason the JLabel (problem) I am adding to the JPanel (panel) is not showing up. Why is this occurring? Any explanations, I am using both the repaint, and validate methods but still nothing shows up. 回答1: The problem you're having is you're blocking the Event Dispatching Thread, prevent the UI from been updated or any new events from been processed... It starts here... for(int i = 0; i < 15; i++) { //... //Check

Does adding a JLabel to a JPanel “hide” the JPanel?

谁说我不能喝 提交于 2019-11-26 06:08:44
问题 If I have a few JPanels in a GridLayout, each one with a MouseAdapter, and then create JLabels (with text) and add to each one of the JPanels. Note the JLabels have no listeners. If I render this and try to click on a JPanel, or, ultimately try to click on the JLabel, will the MouseAdapter register that as an event? Basically I want the JPanels to register events and the JPanels to just display text on-top of the JPanels. Also, the panels have background color. If the JLabel does \"hide\" the

Can&#39;t a Swing component be added to multiple containers?

寵の児 提交于 2019-11-26 06:02:24
问题 I\'m trying (testing something else) to add one JButton reference into two JPanels to test it, and it disappears from the first panel it was added to! So, can\'t a Swing component be added to multiple containers? Thank you in advance. 回答1: From: http://download.oracle.com/javase/tutorial/uiswing/components/toplevel.html: Each GUI component can be contained only once. If a component is already in a container and you try to add it to another container, the component will be removed from the

JPanel which one of Listeners is proper for visibility is changed

丶灬走出姿态 提交于 2019-11-26 05:56:49
问题 Are there some rules, or good/bad experiences with AncestorListener , ComponentListener or HierarchyListener listening for visibility of changes with JPanel and JComponents ? Is one of them better or safer than the others? I would especially like to know about when and how JPanel / JComponent is hidden. Notice the following code contains incorrect Swing rules, like using Thread.sleep(int) , in this case, to allow me to print-out correct order of Listeners in Swing GUI import java.awt

Drawing rectangle on a JPanel

白昼怎懂夜的黑 提交于 2019-11-26 05:56:47
问题 I want to draw a recangle on a JPanel. Am able to draw with the following code. public class DrawingColor extends JFrame { public static void main(String[] args) { DrawingColor d = new DrawingColor(); } public DrawingColor() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().add(new MyComponent()); setSize(400,400); setVisible(true); } public class MyComponent extends JComponent { @Override public void paint(Graphics g) { int height = 200; int width = 120; g.setColor(Color.red