jpanel

How to remove a JButton in a JButton matrix?

十年热恋 提交于 2020-01-25 14:15:10
问题 I want to remove a certain botton using MouseListener from a matrix of bottons and add a JLabel in the empty, so I use: import java.awt.*; import java.awt.event.*; import javax.swing.*; public MyClass(){ object = new Object(); bottons = new JButton[5][5]; labels = new JLabel[5][5]; myPanel = new JPanel(); myPanel.setLayout(new GridLayout(5,5)); click =false; for(int i = 0 ; i<5 ; i++){ for(int j = 0; j<5 ; j++){ myPanel.add(bottons[i][j] = new JButton()); } } } public void mouseReleased

How to remove a JButton in a JButton matrix?

风流意气都作罢 提交于 2020-01-25 14:13:23
问题 I want to remove a certain botton using MouseListener from a matrix of bottons and add a JLabel in the empty, so I use: import java.awt.*; import java.awt.event.*; import javax.swing.*; public MyClass(){ object = new Object(); bottons = new JButton[5][5]; labels = new JLabel[5][5]; myPanel = new JPanel(); myPanel.setLayout(new GridLayout(5,5)); click =false; for(int i = 0 ; i<5 ; i++){ for(int j = 0; j<5 ; j++){ myPanel.add(bottons[i][j] = new JButton()); } } } public void mouseReleased

How to remove a JButton in a JButton matrix?

一世执手 提交于 2020-01-25 14:13:18
问题 I want to remove a certain botton using MouseListener from a matrix of bottons and add a JLabel in the empty, so I use: import java.awt.*; import java.awt.event.*; import javax.swing.*; public MyClass(){ object = new Object(); bottons = new JButton[5][5]; labels = new JLabel[5][5]; myPanel = new JPanel(); myPanel.setLayout(new GridLayout(5,5)); click =false; for(int i = 0 ; i<5 ; i++){ for(int j = 0; j<5 ; j++){ myPanel.add(bottons[i][j] = new JButton()); } } } public void mouseReleased

Adding a background Image to JPanel

随声附和 提交于 2020-01-24 00:23:14
问题 I get error's with any threads I could find about this issue. Pretty much I just was to add a background to my JPanel. My code: package org.client; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing

Trying to draw lines with JPanel

一笑奈何 提交于 2020-01-22 16:14:06
问题 I am trying to draw lines using JPanel and I have hit somewhat of a wall. I can get two sides down but once it comes to subtracting from the x cord it all goes wrong. package GUIstuff; import java.awt.Graphics; import javax.swing.JPanel; public class DrawPanel extends JPanel{ public void paintComponent (Graphics g){ super.paintComponent(g); int width = getWidth(); int height = getHeight(); int drawCounter = 0; // counters for all the while statements int drawCounter2 = 0; int drawCounter3 = 0

How to draw on JPanel on fixed position?

◇◆丶佛笑我妖孽 提交于 2020-01-21 18:58:08
问题 I have JPanel wrapped in JScrollPane and I want the rectangle to be drawn always on the same position = moving with scrollbars wont affect the visibility of the rectangle. I tried following code: public void paintComponent(Graphics g) { g.setColor(Color.red); g.drawRect(50, (int)getVisibleRect().getY(), 20 , 20); } but it only repaints the rectangle when size of whole JPanel is changed. 回答1: IIRC, JScrollPane will try to minimise the amount of redrawing done scrolling, so it wont always cause

BoxLayout refuses to honor preferred size of JButton

混江龙づ霸主 提交于 2020-01-21 15:26:45
问题 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(

BoxLayout refuses to honor preferred size of JButton

混江龙づ霸主 提交于 2020-01-21 15:25:33
问题 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(

What is the proper way to swap out an existing JPanel in a JFrame with another?

徘徊边缘 提交于 2020-01-20 08:53:08
问题 I'm building a program that requires swapping out the current, visible JPanel with another. Unfortunately there seems to be multiple to go about this and all of my attempts have ended in failure. I can successfully get the first JPanel to appear in my JFrame, but swapping JPanels results in a blank JFrame. My Main JFrame: public class ShellFrame { static CardLayout cl = new CardLayout(); //handles panel switching static JFrame frame; //init swing on EDT static MainMenu mm; static Panel2 p2;

Nullpointerexception with JPanel

半世苍凉 提交于 2020-01-17 08:47:45
问题 When I m trying to call panel2 inside actionPerformed method, I m getting nullpointerexception. Plz help me in getting out of this silly prblm. public class PanelEventTest implements ActionListener { /** * @param args */ JFrame frame; JPanel panel1, panel2; String[] list = {"Sachin","Tarun","Vipin"}; JList jlist; JButton next; void originalFrame() { frame = new JFrame(); frame.setSize(500, 300); frame.setVisible(true); frame.setLayout(new FlowLayout()); frame.add(panel1()); frame.add(panel2()