jpanel

Is there a better way to set an initial position for a JPanel graphic?)

不问归期 提交于 2019-12-02 05:10:53
问题 In Chapter 15 of Liang's Intro to Java Programming (7th ed.) , he introduces a program to make a (2-D) ball on a JPanel and enlarge it upon clicking enlarge/shrink buttons. I've modified the program so that it also 1) enlarges/shrinks the ball if the user clicks/option+clicks, 2) allows you to pick the color of the ball by pressing a button, and 3) allows you to move the circle by dragging it with your mouse. The last modification is what was giving me trouble for a while, because I wanted to

Alignment issue in GridBagLayout

混江龙づ霸主 提交于 2019-12-02 05:03:18
问题 Please have a look at the following code import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TestForm extends JFrame { private JLabel heightLabel, weightLabel, waistLabel, neckLabel, hipsLabel,bfPercentageLabel; private JTextField heightTxt, weightTxt, waistTxt, neckTxt, hipsTxt; private JPanel centerPanel; private JPanel southPanel; private JLabel endTargetWeightLabel; private JLabel endTargetWeightResultLabel; private JLabel fatMustLoseLabel; private JLabel

When creating a BufferedImage from a JPanel (w/o a JFrame), can I also use a layout manager?

落花浮王杯 提交于 2019-12-02 04:47:28
问题 I am trying to create a BufferedImage from a JPanel, without using a JFrame. Yesterday, I was finally able to get the image to appear with help from this community (see below), but now I'm having some layout trouble. All of the components on the BufferedImage begin drawing at 0,0, instead of following the layout manager. Does anyone know of a solution for this problem? Yesterday's question: Can I create a BufferedImage from a JPanel without rendering in a JFrame? In the code below, the two

MiGLayout will not expand JPanel down

对着背影说爱祢 提交于 2019-12-02 04:41:18
问题 As I am sure some of you are aware, I am attempting to make an alernative tool to Tiled that is open source. I asked before what layout I should use and I was suggest the MiGLayout which I really do love, but don't understand that well at all. I also hope to learn something from this as well. What I would like is someone to explain to me what I did wrong, obviously, and what I need to do to correct this. Let me first state what works perfect in my eyes, but may not really. JFrame Menu & Menu

Add components directly to JFrame, or put them inside a JPanel?

梦想与她 提交于 2019-12-02 04:38:11
I have a general question regarding java GUI. If I have several components that I want to add to a JFrame, should i put them directly inside the JFrame, or add them to a JPanel, and then add the panel to the frame? If adding the components to a JPanel first is the best, why? I usually do this, then I understood that I have no idea why/if this is more optional then adding directly to the frame. JFrame also have layout managers, so it's possible to get them in the correct position. When you add components to the frame you add the components to the content pane of the frame. The content pane is a

Add transparent JPanel upon AWT Component to paint on

不想你离开。 提交于 2019-12-02 04:27:02
问题 I've got a Problem: In my Java application I've got an AWT Component (cannot change that one) that streams and shows an avi-file. Now I want to draw upon this movie and thought about putting a transparent JPanel above it and draw on that one. This does not work since I either see the avi-stream or the drawn lines but not both. I read somewhere that AWT does not support transparency of components - but the panel is a JPanel which is able to do so. Can someone please help me with this one -

Add Object to JPanel after button click

放肆的年华 提交于 2019-12-02 04:17:00
I have created a JScrollPane with a JPanel inside it and I want to add JPanel/JLabel/Other objects after pressing the button. For example after three button presses I want to get something like this: I tried myJPane.add(testLabel) with testlabel.setBounds() but no result, I don't want to use GridLayout because of the unchangeable sizes. I would like it if the added objects had different sizes - adjusted to the text content. What should I use for it and how? Thanks in advance. Best regards, Tom. Here is a JPanel inside a JScrollPane that adds JLabel s to it when pressing the button: public

BorderLayout doesn't show correctly

风格不统一 提交于 2019-12-02 04:14:21
I want to have a JFrame, where on the left and the right there is a border that has the color black and a width of withfOfJFrame/10. Now, my try at it looks like this: JFrame f = new JFrame(); f.setSize(800, 600); f.setLayout(new BorderLayout()); JPanel leftBorder = new JPanel(); JPanel rightBorder = new JPanel(); leftBorder.setBackground(Color.black); rightBorder.setBackground(Color.black); leftBorder.setSize(f.getWidth()/10, f.getHeight()); rightBorder.setSize(f.getWidth()/10, f.getHeight()); JPanel center = new JPanel(); center.setBackground(Color.red); f.add(leftBorder, BorderLayout.WEST);

Switching between JPanels in a JFrame

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 04:04:59
Now I know there are many, many questions on this and I've read a dozen. But I've just hit a wall, I can't make heads or tails of it. Heres my question. I have 3 Panel classes. ConfigurePanel.java ConnectServerPanel.java RunServerPanel.java and my JFrame class StartUPGUI.java This is what is initialised at startup private void initComponents() { jPanel1 = new javax.swing.JPanel(); startUp = new sjdproject.GUI.ConfigurePanel(); runServer = new sjdproject.GUI.RunServerPanel(); serverConnect = new sjdproject.GUI.ConnectServerPanel(); setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING

Jbutton over Jbutton background image?

可紊 提交于 2019-12-02 03:47:48
问题 Lets say I created a 2d tile map with jbuttons and then created units on top of the map is there a way to show the background of the map when the unit(also a jbutton) is on top of the tile, because how it is now is the background of the unit is just colored red, so is it possible to do this with jbuttons over jbuttons? 回答1: Possible, yes, advisable, ah, probably not. I believe you're going to need to change the layout of the title button to something you can control (this is going to depend