jpanel

JPanel fills all JFrame space

人盡茶涼 提交于 2019-12-02 03:46:27
问题 I have write this code for displaying some set of colors from panel: import java.util.ArrayList; import java.util.List; import javax.swing.JFrame; import javax.swing.JPanel; public class Palette { public static void main(String[] args) { JFrame frame = new JFrame("Panel"); palette.add(new Color(255, 0, 0)); palette.add(new Color(0, 255, 0)); palette.add(new Color(0, 0, 255)); int width = 100; int height = 250; int x = 0; for (Color color : palette) { JPanel panel = new JPanel(); panel.setSize

Adding oval shape to JPanel

梦想的初衷 提交于 2019-12-02 03:27:27
问题 Here's my simple code. I don't really know how to add a drawn oval to a JPanel . I did some paintings before, but I have never used the constructor so I don't have an idea. public class Buffer extends JPanel{ public JFrame frame; public JPanel panel; public Buffer(){ frame=new JFrame(); panel=new JPanel(); panel.setSize(500,500); panel.setBackground(Color.red); frame.setSize(500,500); frame.setVisible(true); frame.add(panel); } public void paintComponent(Graphics g){ super.paintComponents(g);

Adding JPanel to JScrollPane

走远了吗. 提交于 2019-12-02 02:55:35
I have a gui which has a Panel that contains a sequence of labels and TextFields and uses a spring layout(this is the mainPanel) and another Panel that just contains a button(buttonPanel). I am trying to make my mainPanel to have a vertical scrollbar as well. I would like to implement my GUI such that within the JFrame I have 2 panels. The mainPanel appears on the top of the frame and the buttonPanel appears below the mainPanel. My problem is I am not able to make the Panels appear such that the buttonPanel is below the mainPanel and I am also not sure how to add a scrollbar to the mainPanel.

For glasspane purposes, why are input elements in Swing seemingly not considered part of a JPanel?

余生长醉 提交于 2019-12-02 02:44:43
问题 By input elements I mean things like JSpinners and JComboxBoxes. My glasspane is passed a JPanel containing JSpinners, JComboBoxes and for the most part, JLabels. The glasspane has a MouseListener attached. The surprising thing is that mouseEntered is called upon the mouse cursor leaving the input elements and hovering over the other parts or empty space of the JPanel! Is this normal behaviour? How can I get the input elements to be considered part of the JPanel for Glasspane purposes? Here

For glasspane purposes, why are input elements in Swing seemingly not considered part of a JPanel?

纵饮孤独 提交于 2019-12-02 02:38:10
By input elements I mean things like JSpinners and JComboxBoxes. My glasspane is passed a JPanel containing JSpinners, JComboBoxes and for the most part, JLabels. The glasspane has a MouseListener attached. The surprising thing is that mouseEntered is called upon the mouse cursor leaving the input elements and hovering over the other parts or empty space of the JPanel! Is this normal behaviour? How can I get the input elements to be considered part of the JPanel for Glasspane purposes? Here is a screenshot of my UI with its input elements and jLabels. Here is an example piece of Code: import

Jbutton over Jbutton background image?

一笑奈何 提交于 2019-12-02 02:32:07
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? 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 upon your visual requirements). I, personally, would probably go for a panel with a label inside it, using

How to draw a spiderchart above a existing JfreeChart

不问归期 提交于 2019-12-02 02:25:25
I have one a jfree chart which I can generate everytime I run the code. Now i want to override few more spider graphs on the same chart. please help me how to do that Above this i need to add one more spider chart using jfree. Here is my code for doing this chart. package com.rectrix.exide.pdfbox; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.GradientPaint; import java.awt.Paint; import java.awt.PaintContext; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.geom.AffineTransform; import java.awt

BoxLayout refuses to honor preferred size of JButton

好久不见. 提交于 2019-12-02 02:24:12
I have been working on a small project that is supposed to simulate a gambling game. Unfortunately, I ran into some odd issues while working with BoxLayout . To the best of my knowledge, LayoutManager s usually honor any component's preferred size. However, in the below code, BoxLayout does not. Here is my code thus far: import java.awt.*; import javax.swing.*; public class Main { public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("Suit-Up"); frame.setContentPane(makeGUI()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame

Add multiple Polygon objects on the same JPanel frame

天涯浪子 提交于 2019-12-02 02:13:55
So I have a DrawStar class that draws a star using Polygon like that: public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; int[] cX = new int[] {x, x+5, x+20, x+8, x+16, x, x-16, x-8, x-20, x-5, x}; int[] cY = new int[] {y, y+14, y+14, y+22, y+39, y+29, y+39, y+22, y+14, y+14, y}; Polygon pol = new Polygon(cX, cY, 11); g2.setColor(this.color); g2.draw(pol); g2.fillPolygon(pol); } Then in my main class I create a JPanel frame to draw the stars: ... JFrame starsframe = new JFrame(); starsframe.setTitle("Random stars..."); starsframe.setSize(600, 400); starsframe

Drawing the Quadratic formula with sliders on a JPanel

末鹿安然 提交于 2019-12-02 01:52:42
问题 So, I'm trying to make a program where you can input the quadratic formula (ax^2+bx+c) via sliders. Then it draws a graph as you adjust for A, B, and C. Issues: I want the stuff I wrote in super paint and the sliders to be in one place. The sliders are in place when I run it. There's space with the correct background where I want my graph in the panel but no actual graph. Here's my driver class: import java.awt.*; import javax.swing.*; public class quadraticslider { public static void main