jpanel

Choosing the layout managers and number of panels for Java GUI

我的未来我决定 提交于 2019-12-03 18:04:55
问题 I would appreciate, If anyone here is kind enough to recommend me what are the layout managers to choose and how to separate the attached GUI into Jpanels. Thanks so much in advance. What I have tried so far: Jframe - BorderLayout Map (the grid and clear button from another class extending jpanel) - so I have put it in jframe.CENTER the buttons to the right: jframe.EAST I put them in a jpanel in a gridlayout (but I cannot get the spacing between the components) buttons at the bottom: jframe

Adding JPanel to JFrame

試著忘記壹切 提交于 2019-12-03 17:45:51
问题 I have a program in which a JPanel is added to a JFrame: public class Test{ Test2 test = new Test2(); JFrame frame = new JFrame(); Test(){ ... frame.setLayout(new BorderLayout()); frame.add(test, BorderLayout.CENTER); ... } //main ... } public class Test2{ JPanel test2 = new JPanel(); Test2(){ ... } } I get an error asking me to change type of 'panel' to 'component'. I do I fix this error? It wants me to do: Component panel = new Component(); 回答1: public class Test{ Test2 test = new Test2();

JLabel and JLayeredPane - How to display an image over another image?

泄露秘密 提交于 2019-12-03 17:04:17
I try to create a little game in java but I'm in trouble. When I draw a map, I'm not able to display the characters without overwrite the titlesets of the squares. My goal is to be able to display many pictures on the same square (like the titleset of the grass, the character and a tree), so I have to deal with the transparency of my pictures (this is not the problem) and the layer (it is the problem). So how can I display an image on another image? How can I explain to java that I need to display this image on or under another image? This is my source code. I don't know is that can help you.

Resizing jPanels with animation

放肆的年华 提交于 2019-12-03 15:26:06
I am developing an application with a FullScreen Panel, and sometimes I need to show a second Panel, in the right side of the screen. To develop it I made a jPanel with AbsoluteLayout (from NetBeans) containing another two panels. I calculate each panel position and size relative to the screen resolution. Basically, I have two "states". In the first the jPanel1 has width = 100% and the jPanel 2 has width = 0% (So I am not showing this panel). And the second state, when jPanel1 has width = 75% and jPanel2 has width = 25%. To do these transitions I only recalculate each panel size and it works

How to have Collapsable/Expandable JPanel in Java Swing

拥有回忆 提交于 2019-12-03 12:52:58
I want a JPanel that can be Collapsed or Expanded when user clicks on a text/icon on its border. I need this type of panel due to space crunch in my application. I read about CollapsiblePanel class but not sure how to use it.. I think SwingX is needed to be downloaded but did not find that anywhere. Moreover, it would be better if I get the solution to this in basic Java Swing. not sure where you looked, but it's not that difficult to find - even given the infrastructure mess we are in ;-) Go to the project home of SwingX , then follow the link in the first paragraph to the (barebone) download

adding JLayeredPane to JPanel

南楼画角 提交于 2019-12-03 12:32:13
I am trying to add a JLayeredPane to a JPanel and then add an image (JLabel icon) and a button to the JLayeredPane, but neither show up. I've tested the image without the button and the layeredpane so I know that works. Here is some of the code I am using. Is there something I am missing or doing wrong? public class MyClass extends JPanel { private JLayeredPane layeredPane; private JLabel imageContainer = new JLabel(); private JButton info = new JButton("i"); MyClass(ImageIcon image) { super(); this.imageContainer.setIcon(image); this.layeredPane = new JLayeredPane(); layeredPane

How to make JLabels start on the next line

筅森魡賤 提交于 2019-12-03 11:53:18
JPanel pMeasure = new JPanel(); .... JLabel economy = new JLabel("Economy"); JLabel regularity = new JLabel("Regularity"); pMeasure.add(economy); pMeasure.add(regularity); ... When I run the code above I get this output: Economy Regularity How can I get this output, where each JLabel starts on a new line? Thanks Economy Regularity John Kugelman supports Monica You'll want to play around with layout managers to control the positioning and sizing of the controls in your JPanel . Layout managers are responsible for placing controls, determining where they go, how big they are, how much space is

How to add padding to a JPanel with a border

百般思念 提交于 2019-12-03 10:33:02
I want to add padding to some JPanel s. I found this answer: https://stackoverflow.com/a/5328475/1590323 It worked fine for a panel without a border. But how do I do it for a panel that already has a border? (A TitledBorder in this case) I tried: JPanel mypanel = new MyPanel(); // Panel that I am going to add a TitledBorder to, but needs padding mypanel.setBorder(new EmptyBorder(10,10,10,10)); JPanel mypanel_container = new JPanel(); TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createRaisedBevelBorder(), "My panel"); border.setTitleJustification(TitledBorder.LEADING);

Adding JPanel to JFrame

十年热恋 提交于 2019-12-03 06:57:39
I have a program in which a JPanel is added to a JFrame: public class Test{ Test2 test = new Test2(); JFrame frame = new JFrame(); Test(){ ... frame.setLayout(new BorderLayout()); frame.add(test, BorderLayout.CENTER); ... } //main ... } public class Test2{ JPanel test2 = new JPanel(); Test2(){ ... } } I get an error asking me to change type of 'panel' to 'component'. I do I fix this error? It wants me to do: Component panel = new Component(); public class Test{ Test2 test = new Test2(); JFrame frame = new JFrame(); Test(){ ... frame.setLayout(new BorderLayout()); frame.add(test, BorderLayout

Zoom JPanel in Java Swing

蓝咒 提交于 2019-12-03 05:52:25
I have an existing Java Swing application. In the middle of the application is a single JPanel which I want to be able to zoom in and out of. The JPanel has a number of JComponents on it (mostly other JPanels and JLabels ). Also mouse position will need to be adjusted appropriately as well - so mouseevents need to remain same even after the JPanel has been zoomed. As such simply changing the paint methods of each component doesn't seem plausible. EDIT: OK i kind of got it working using the MagnifierUI class with some minor edits. However the magnified panel I create has the wrong mouseevents -