jpanel

JLabel not visible on Jpanel

荒凉一梦 提交于 2019-12-11 02:44:22
问题 I'm working on a program in which I'd used a JTextArea , JButton , JLabel and JPanel . The logic I'd to implement is: user types a text in the given textArea and then click on the button . On button click I'd to retrieve the text from the textArea and create a label with the written text(as in textArea ) and show it on the panel . Everything I'd done previously is correct but the problem is with the label and panel . The label is not visible on the panel . The code snippets is: import java

Moving JPanels using TimerTask

感情迁移 提交于 2019-12-11 02:40:08
问题 So I have set up a Java GUI like the one pictured below (apologies for horribly painted recreation): Layout for Java GUI All of the JPanels are equal size (not shown well in the drawing). What I'm trying to do is make it so that when I am doing something with the progress bars (I.E reading some text files in), the JPanels will cycle through. As in the red one will go to the bottom, the orange one will go to the top, and thus keep going in this cycle. I'd like them to change every half second

Drawing inside multiple JPanels

感情迁移 提交于 2019-12-11 02:38:12
问题 I have three JPanels inside a main Frame. Clockwise from the left, in the first panel I plan to have some controls which dictate the drawing on the panel 2. The third bottom panel will show some informations. What I understand is, I have to override paintComponent so that I can achieve the desired effect on the second panel. Right now I just want to test it, whether I can draw simple texts on this panel. But in fact, I am having problem to draw anything in any of the three panels. The code is

jPanel is not refreshing until I resize the app window

半腔热情 提交于 2019-12-11 02:18:20
问题 I have one problem with my jPanel. I have a button which PNG image from String input (math formula) and then it will repaint the old image in jPanel. And there goes the problem. The image got changed, but the jPanel wont repaint until I manually resize the app window. Looks like the Panel wont repaint until that resizing. But I have no idea how to do it in that button. I tried this and this but no change. btw. I am using GUI Builder in netbeans. My code... first attempt: public class

Transfer jtoolbar from one jpanel to another

本秂侑毒 提交于 2019-12-11 02:01:44
问题 This is my first question, so bear with me. Let's say that I have 2 JPanel and 1 JToolBar. What I want to do is drag the toolbar from one panel to another and, after mouse release, the toolbar should stick to the second. 回答1: BasicToolbarUI has floatAt method. As you can see from source (below) toolbar uses docing source which is toolbar's parent container. You can try to override the method and replace the source. protected void floatAt(Point position, Point origin) { if(toolBar.isFloatable(

How can I make an image the same size as the panel?

喜夏-厌秋 提交于 2019-12-11 01:58:41
问题 I created a simple frame program that includes a image. But the image don't have the same size as the frame. If i enlarge the frame the image size stays the same? How can i make the image the same size as the frame? Here is my current code: JPanel panel1 = new JPanel(); ImageIcon image1 = new ImageIcon("C:\\Users\\Dark Mangetsu\\Downloads\\Ceng102_Lab10.1\\image\\flower.jpg"); JLabel label1 = new JLabel(image1); panel1.add(label1); Color color1 = new Color (200, 0 ,100); panel1.setBorder

I can't get graphics to draw on my panel/canvas/window in my Java program (swing). Any Ideas?

佐手、 提交于 2019-12-11 01:53:33
问题 I can't get graphics/text to draw on my panel/canvas/window in my Java program (using swing). I even tried breaking it up into two classes, with the paintComponent in one (extends JPanel) and other stuff in another class (extends JFrame). I've tried a panel with a Canvas and without a Canvas (both the same results). I can't get anything to draw in the blue area. If I remember correctly, when I tried it with no panels at all, I did see graphics. I've successfully done this program in text (no

Why Are My Buttons Taking Up The Whole JFrame?

醉酒当歌 提交于 2019-12-11 01:50:04
问题 My code was working before, but now one JButton takes up the entire JFrame, any help would be appreciated! I am using a FlowLayout called fl and a class called Ken I have ten buttons called (oneButton, twoButton, threeButton, etc..) MY CODE: import java.awt.ComponentOrientation; import java.awt.Dimension; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; public class Ken { public static void frame(){ JFrame frame = new JFrame("Pow"); frame.setSize(500, 600);

JPanels and GridLayouts

此生再无相见时 提交于 2019-12-11 01:37:59
问题 I have been attempting to recreate this in Java: http://imgur.com/pjt7SMZ This is the code I have so far: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Display extends JFrame implements ActionListener { private static final int FRAME_WIDTH = 400; private static final int FRAME_HEIGHT = 350; private static final int FRAME_X_ORIGIN = 100; private static final int FRAME_Y_ORIGIN = 75; private JButton readFileButton; private JButton exitButton; private JButton

panel with image background and mouse draw

故事扮演 提交于 2019-12-11 01:33:57
问题 How can I use a image as background in a JPanel if the paint () method is already used for other purposes? (I'm tried to draw over a image in a panel). Here is my code to draw as a pencil, but I don´t know how to add the image as background ? @Override public void paint(Graphics g) { if (x >= 0 && y >= 0) { g.setColor(Color.BLACK); g.fillRect(x, y, 4, 4); } } Thanks Diego 回答1: Suggestions: Don't draw in the JPanel's paint(...) method but rather use it's paintComponent(...) method. There are