jpanel

Working with layout managers

别来无恙 提交于 2019-12-25 18:33:49
问题 I'm trying to make a kitchen display system using a FlowLayout and I'm trying to figure out a way to add another panel on the 2nd row when the first row is already full. The width of the GUI will change according to user preference. When wider, it should show more of the components per row. 回答1: Approach - Variable width with WrapLayout The GridLayout solution presumes the GUI requires 6 components per row. For as many cols as needed to fill the width, & then show the components in as many

Working with layout managers

假如想象 提交于 2019-12-25 18:33:37
问题 I'm trying to make a kitchen display system using a FlowLayout and I'm trying to figure out a way to add another panel on the 2nd row when the first row is already full. The width of the GUI will change according to user preference. When wider, it should show more of the components per row. 回答1: Approach - Variable width with WrapLayout The GridLayout solution presumes the GUI requires 6 components per row. For as many cols as needed to fill the width, & then show the components in as many

Java: mouse hit detection with overlapping JComponents

孤者浪人 提交于 2019-12-25 16:58:23
问题 I have a JPanel with null layout. On this panel I draw some custom JComponents as markers, little red rounds, and lines. When the line is not horizontal or vertical, the JComponent's "sensitive area" is a rectangle which has as hypotenuse the line itself. This excessive area often "steals" MouseEvents to the markers. How can I make MouseEvents "pass" to the covered objects, if the user is not clicking the real line? 回答1: The correct approach is that suggested by moonwave99. 1) Create and

Swing: Would drawing graphic in a JPanel changes its dimension?

不问归期 提交于 2019-12-25 14:46:53
问题 I got a JPanel class and its method paintComponent() is overridden to draw a custom chart. Would the panel's dimension be stretched if I drew a graphic bigger than the panel? If answer is no, how could I make it so? 回答1: Would the panel's dimension be stretched if I drew a graphic bigger than the panel? No it would not stretch. ..how could I make it so? Easiest way: Instead of putting the logic of drawing the graph into the paint method, put that logic into drawing an image of the correct

How to add buttons and JPanels to a ZOrderComponent?

走远了吗. 提交于 2019-12-25 10:05:09
问题 I'm trying to create a JFrame with a background image, a JLabel over the background image centered and toward the bottom, with two buttons on the right and left that say "Stay" and "Leave". This is already created. The issue arises with the order of each of the items. I cannot get the JLabel with text and buttons over the background image, with both of them showing. Here is my code; any advice would be appreciated. Thank you in advance. public class SceneOne { public static void main(String[]

My JscrollPane isn't scrolling (vertically) the entire image,

自闭症网瘾萝莉.ら 提交于 2019-12-25 09:39:37
问题 when I increase the preferredSize, more of the Bufferedimage(on a JPanel, on a JFrame) is found. The size of the image is going to vary depending on the size of the file my program is reading, where I set the scrollpane; public Frame(String title, int theWidth, int theHeight) throws FileNotFoundException { super(String.format("Title", title)); this.width = theWidth; this.height = theHeight; this.panel = new Panel(width, height); this.scroller = new JScrollPane(this.panel); this.panel

JPanel and Java layout managers

那年仲夏 提交于 2019-12-25 08:16:53
问题 Having read over the internet about JPanel for a while I feel I still need clarification after reading it. My questions: What is JPanel mostly used for? Which layout manager is most flexible to use? How do you position components at certain areas using layout managers? I find it really difficult to position components at certain areas within the container using a layout manager. What layout manager do you recommend I use or do you have to use a mixture of different ones? 回答1: My first

Trouble Drawing In JPanel

本小妞迷上赌 提交于 2019-12-25 07:35:19
问题 I'm going to start off by saying that I can almost guarantee that this question is going to be a copy but I couldn't find any other answers that suited my needs / worked on my program. I need to draw on a JPanel , but I can't seem to be able to get the line I need to draw to show up. JFrame drawF = new JFrame("Simulator"); JPanel simPanel = new JPanel(); drawF.setVisible(true); drawF.setSize(1000,650); drawF.add(simPanel); drawF.pack(); simPanel.setLayout(null); simPanel.setSize(1000,650);

SetBounds not working properly

坚强是说给别人听的谎言 提交于 2019-12-25 07:07:08
问题 I want to make 3 panels, where one is to the west side, one to the east, and one to the south. When I complie this, it gives me frame with colors all one above another and it doesn't give me buttons. frame = new JFrame(); frame.setBounds(600, 200, 500, 350); frame.setTitle("Dr. Idrizovic"); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panelWest = new JPanel(); panelWest.setBounds(0, 0, 175, 310); panelWest.setLayout(null); panelWest.setBackground(Color.green);

adding multiple buttons using JPanels

蹲街弑〆低调 提交于 2019-12-25 06:32:05
问题 I have created a simple compass program that moves the GUI box around the screen and I am now progressing on to adding NE, NW etc. This involves using JPanels as this allows multiple objects. My issue is that I've made 9 separate panels for the separate buttons but I have no idea how to add them to the JFrame as everything I do doesn't seem to work. Any ideas would be appreciated. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MovingCompassExtraJFrame extends