jpanel

Java : set a Component on top of another

坚强是说给别人听的谎言 提交于 2019-12-10 14:15:30
问题 I am writing a program in java. I have a main JPanel that has two JPanel and one Canvas added on it. I aim to resize the Canvas while running the program. When I maximized the Canvas i want it to be always on top of the other component. How can I set this property for my Canvas? 回答1: You could replace your main JPanel with a JLayeredPanel. A layered panel will let you specify that some child components should be layered above other child components. I.e.: JLayeredPane pane = new JLayeredPane(

How to find out the preferred size of a JPanel which is not displayed, according to its content?

橙三吉。 提交于 2019-12-10 14:07:57
问题 I am using a JPanel (with several labels inside) to add a dynamic information on a graph. This panel is dynamically created, it is not visible before I use it to draw. For this, I am using a BufferedImage, and I follow approximately the same steps as described on this other question. It works good, as long as I specify all sizes (the panel, and its components). Like asked as well in comments of the referred question, how can I determine the optimal size of this panel? The same operation would

java JPanel How to fixed sizes

随声附和 提交于 2019-12-10 12:39:22
问题 I want to have a resizable panel, that always has the top green panel of a fixed depth. i.e. all changes in height should effect the yellow panel only. My code below is almost OK, except the green panel varies in size a little. How do I do this? Panel.setLayout(new BoxLayout(Panel, BoxLayout.Y_AXIS)); Panel.setAlignmentX(Component.LEFT_ALIGNMENT); JPanel TopPanel = new JPanel(); TopPanel.setPreferredSize(new Dimension(80,150)); TopPanel.setVisible(true); TopPanel.setBackground(Color.GREEN);

Image did not fresh in Frame on Mouse Click In Java

狂风中的少年 提交于 2019-12-10 12:19:02
问题 First Time three random images shown on Jframe from three diffrent arrays. even MouseClicked Method triggered but images does not refresh in Frame. I want to refresh three random images each time i click on Frame. Please help import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Random; import javax.swing.*; public class Cards extends JFrame implements MouseListener { public static void main(String[] args

getting null pointer exception when adding a panel to a frame

寵の児 提交于 2019-12-10 11:59:25
问题 Update: I've tried to solve the problem by making the panel just the way the other one was made but I'm getting this exception Exception in thread "main" java.lang.NullPointerException at java.awt.Container.addImpl(Container.java:1040) at java.awt.Container.add(Container.java:926) at Plotter.createLayout(Plotter.java:48) at Plotter.<init>(Plotter.java:37) at Plotter.main(Plotter.java:325) and this the code which the I get the error from(Plotter.java) : (the parts I have added are

Resizing JPanel to prepare for printing without removing it from its original position

谁都会走 提交于 2019-12-10 11:28:22
问题 In my program I frequently need to print various JComponents (generally JPanels) and I like them to be full-page. The way I do it now is by using the following code: g2d.scale(pf.getImageableWidth()/componentToPrint.getWidth(), pf.getImageableHeight()/componentToPrint.getHeight()); but this often stretches or otherwise deforms whatever I am trying to print, and I would much prefer to do something that re-sized intelligently, perhaps a functional version of: componentToPrint.setSize(pf

How to make scrollable to jPanel

笑着哭i 提交于 2019-12-10 11:27:33
问题 I am making swing application. And there is too much height of my jPanel. So I want to make this panel as scrollable.: Following is my description of my requirement. I have four jpanel in one jpanel I mean: JPanel p1=new JPanel(); JPanel p2=new JPanel(); JPanel p3=new JPanel(); JPanel p4=new JPanel(); I am adding p2, p3, p4 inside p1 like following output: like above showing panel has more height than computer screen height. So I want to display all content of my panel on computer screen by

How do I remove an old JPanel and add a new one?

断了今生、忘了曾经 提交于 2019-12-10 10:55:54
问题 I would like to remove an old JPanel from the Window (JFrame) and add a new one. How should I do it? I tried the following: public static void showGUI() { JFrame frame = new JFrame("Colored Trails"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(partnerSelectionPanel); frame.setSize(600,400); frame.setVisible(true); } private static void updateGUI(final int i, final JLabel label, final JPanel partnerSelectionPanel) { SwingUtilities.invokeLater( new Runnable() { public void

Java Swing transparent JPanels problem

前提是你 提交于 2019-12-10 06:30:06
问题 I'm having A JLayeredPane where I add 3 JPanels. I make the JPanels transparent (no background is set and setOpaque(false)). I draw lines on the JPanels and only the line on the last JPanel which has been added is visible. The lines of the other JPanels are not visible through that top JPanel (even if I have added different zIndexes when adding them). Anybody who knows a solution for this? Why aren't they transparent? I have created a little test program (3 classes). (TestJPanel and

How to make the background gradient of a JPanel

点点圈 提交于 2019-12-10 06:10:18
问题 I want to know how to make background gradient which is in another JPanel. Many articles found in internet,but all of them had demostrated how to overide the paintComponent() of the JPanel not how to do for a jPanel which is inside it. I use Netbeans IDE. I created a new JPanel class and could overide its paintComponent(). I have another jpanel on it (dragged & dropped on to the parent JPanel). I want to make its background gradient. Here is how I tried for parent. It worked. How can I