jpanel

Adding JPanels from other classes to the cardLayout

折月煮酒 提交于 2019-12-17 02:32:07
问题 I've got 3 windows in 3 separate classes and I would like to use cardLayout so that when you click the next button, the next window will appear. How do I add JPanels containing different elements to one cardLayout? This is the first window: (the only difference is the background though - but it represents the idea of how I got it actually) public class Window1 extends JPanel implements ActionListener { static CardLayout cardLayout = new CardLayout(); public Window1() { init(); } private void

What does .pack() do?

↘锁芯ラ 提交于 2019-12-17 02:31:51
问题 I am learning about JPanel and GridLayout , this snippet of code will produce a simple JPanel with 6 buttons package testing; import java.io.*; import java.util.*; import java.security.*; import javax.xml.bind.DatatypeConverter; import java.lang.*; import java.awt.*; import javax.swing.*; public class Testing { public static class GridPanel extends JPanel { public GridPanel() { setLayout(new GridLayout(2,3)); setBackground(Color.GREEN); this.setPreferredSize(new Dimension(500,500)); JButton

Drawing a rectangle that won't disappear in next paint

女生的网名这么多〃 提交于 2019-12-16 22:53:43
问题 I trying to create a JPanel that draws rectangles. The Panel needs to draw alot of rectangles, but they dont move. One solution to my problem was to create an list with all the rectangles i already created and draw they all in every call of "Paint". But there is a lot of rectangles and it slows the computer. I also tried to use repaint(x, y, height, width) to rapaint just the space of the new rectangle but it did not work. (JPanel keeps erasing previous rectangles.) In sort, i need to draw

How to paint specific coordinates of one JPanel onto another JPanel

99封情书 提交于 2019-12-14 04:08:58
问题 This is my problem : I have one JPanel and i paint in this panel one rectangle ex. 100x100. In another JPanel I wouldlike show/paint fragments on first JPanel ex. 50x50, but if I change first JPanel, another JPanel change too (dont copy graphics or Panel) What I can do this? First Panel Second Panel Public class Okienko extends JFrame { Panel p = new Panel(); public Okienko(){ //setLayout(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); add(p); pack(); setVisible(true); } private class

How to fix gap in GridBagLayout

我的未来我决定 提交于 2019-12-14 03:49:58
问题 I am using a GridBagLayout to create a JPanel, called 'Preset' that gets replicated several times in a JFrame. Each Preset will have multiple rows (JPanels). My goal is that only one line (the first) will show up, but when the edit button is clicked they will all show. Right now, the edit button works, but there is a massive space between lines. I want it to be that when the extra lines are collapsed, each Preset will be directly above each other (no space). You can see in the following

How to put JFrame into existing JPanel in Java Swing?

那年仲夏 提交于 2019-12-14 03:48:26
问题 I have an open-source java swing application like this: http://i47.tinypic.com/dff4f7.jpg You can see in the screenshot, there is a JPanel divided into two area, left and right area. The left area has many text links. When I click the SLA Criteria link, it will pop-up the SLA Criteria window. The pop-up window is JFrame object. Now, I'm trying to put the pop-up window into right area of the JPanel, so that means no pop-up window anymore, i.e. when I click the SLA Criteria link, its contents

How to add jpanel to a specific cell of GridLayout

余生长醉 提交于 2019-12-14 03:33:56
问题 in the below code, i created a GridLayot with 3 rows and 3 columns, what i want to do is,,to add jpanel_1 into a specifc cell of the Gridlayout, lets say in the grid cell number (2,3). Code : private void setUpGUI2() { // TODO Auto-generated method stub jFrame_2 = new JFrame("Border Demo"); GridLayout gridLayOut = new GridLayout(3,3); jFrame_2.setLayout(gridLayOut); jPanel_1 = new JPanel(new BorderLayout()); jPanel_2 = new JPanel(new BorderLayout()); jPanel_1.setBorder(BorderFactory

NullPointerException continues

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-14 03:32:55
问题 When I am trying to call JPanel panel2 of Panel2 class on triggering of action event from Next JButton of Panel1 class, I am getting NullPointerException. How to resolve this? plzz help. public class PanelEventTest { /** * @param args */ JFrame frame; void originalFrame() { frame = new JFrame(); frame.setSize(500, 300); frame.setVisible(true); frame.setLayout(new FlowLayout()); frame.add(new TestPanel1().panel1()); frame.add(new TestPanel2().panel2()); } public static void main(String[] args)

Centering Panel in Java

跟風遠走 提交于 2019-12-14 03:17:52
问题 For some reason i am having problems centering my panel vertically that is located inside another panel. I do exactly as the examples i studied but still no luck. Down there is my code. Despite using setAlignmentY(0.5f) on my container panel, it still wont center when i resize the window. Also the components inside container panel wont center either, despite setAligenmentX(0.5f). I wonder if there is a solution for this, I pretty much tried everything out there but couldnt find a solution.

swing - get component clicked on JPanel

有些话、适合烂在心里 提交于 2019-12-14 02:15:17
问题 OK so I've got a JPanel with a GridLayout. Each cell of the grid then contains another JPanel. What I'd like to be able to do is have a listener on the "underneath" JPanel which then tells me which of the "overlayed" JPanels was clicked - so I can react to it and the surrounding ones, without making the covering JPanels aware of their position (they change!!) Is there a way of doing this - similar to Determine clicked JPanel component in the MouseListener. Event handling but I couldn't find a