jpanel

Java: Why doesn't this JPanel paint properly?

十年热恋 提交于 2020-01-06 14:51:28
问题 I have a 2D array. I want each pixel to be represented by a total of four in the actual image. I've tried various piece of code but none seem to work and I don't really understand how it works either. So far I have: panel = new JPanel() { @Override public void paint(Graphics g) { Rectangle rect = g.getClipBounds(); g.setColor(Color.white); g.fillRect(rect.x, rect.y, rect.width, rect.height); for (int i = 0; i < m.width(); i++) { for (int j=0; j < m.height(); j++) { g.setColor(Color.red); g

Java: Why doesn't this JPanel paint properly?

99封情书 提交于 2020-01-06 14:50:07
问题 I have a 2D array. I want each pixel to be represented by a total of four in the actual image. I've tried various piece of code but none seem to work and I don't really understand how it works either. So far I have: panel = new JPanel() { @Override public void paint(Graphics g) { Rectangle rect = g.getClipBounds(); g.setColor(Color.white); g.fillRect(rect.x, rect.y, rect.width, rect.height); for (int i = 0; i < m.width(); i++) { for (int j=0; j < m.height(); j++) { g.setColor(Color.red); g

Why is my JFrame just a black window?

冷暖自知 提交于 2020-01-06 14:41:07
问题 My code is this, when I run it I just get a black window and I have no idea why. Thanks for any feedback. Its supposed to print out a picture, and eventually make it move. package assignment04; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; public class GoLDriver { public static void main(String[] args) { GoLModel model= new GoLModel(); JFrame frame = new JFrame(); JPanel panel= new JPanel(); panel.setLayout(new BorderLayout());

Why is my JFrame just a black window?

余生颓废 提交于 2020-01-06 14:39:03
问题 My code is this, when I run it I just get a black window and I have no idea why. Thanks for any feedback. Its supposed to print out a picture, and eventually make it move. package assignment04; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; public class GoLDriver { public static void main(String[] args) { GoLModel model= new GoLModel(); JFrame frame = new JFrame(); JPanel panel= new JPanel(); panel.setLayout(new BorderLayout());

Moving a rectangle in JPanel with arrow keys using KeyListener

半城伤御伤魂 提交于 2020-01-06 08:12:58
问题 I have been trying to make a JPanel move with the arrow keys. It has not been working. I believe it is my inner class that extends the KeyAdapter . I'm also not sure about the ActionListener implemented were it is. The other class I have made does not matter since it is just the frame. package jerryWorlds; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Jerry extends JPanel implements ActionListener{ int SizeX, SizeY, PosX, PosY, VelX, VelY; Image img; Timer

How to make a JPanel scrollable?

浪子不回头ぞ 提交于 2020-01-06 07:54:14
问题 I have a JFrame and In which I want to show a JInternal Frame whihc contains a Jpanel. This JPanel contains some JLabels and JTextFields. As the size of the JInternal Frame is smaller than the size of the JPanel. The JInternal Frame is not resizable so I want to make the jpanel which contains the form should be scrollable. Here is the demo code of it in this code I have not used the JInternal Frame for making it simple. But when I execute this code its not showing scrollbar. Please tell me

JPanel with a background image

[亡魂溺海] 提交于 2020-01-06 03:53:28
问题 I have the following code: class ImagePanel extends JPanel { private Image img; public ImagePanel(String img) { this(new ImageIcon(img).getImage()); } public ImagePanel(Image img) { this.img = img; Dimension size = new Dimension(img.getWidth(null), img.getHeight(null)); setPreferredSize(size); setMinimumSize(size); setMaximumSize(size); setSize(size); setLayout(null); } public void paintComponent(Graphics g) { g.drawImage(img, 0, 0, null); } } and the following: public GUIVenDetails() throws

JScrollPane inside JPanel inside a JTabbedPane is not scrolling

别来无恙 提交于 2020-01-05 12:00:13
问题 I have this JPanel called CatalogPane, which is of size 800 by 600, which is inside a JTabbedPane inside a JFrame called BookFrame. So inside the CatalogPane, I created a JPanel called bookDisplay which displays a list of books and their details. I want it to be of size 780 by 900, leaving 20px for the scrollbar and taller than the frame so that it can scroll. Then I created a panel of size 800 by 400 because I need to leave some extra space at the bottom for other fields. I tried creating a

JScrollPane inside JPanel inside a JTabbedPane is not scrolling

对着背影说爱祢 提交于 2020-01-05 12:00:04
问题 I have this JPanel called CatalogPane, which is of size 800 by 600, which is inside a JTabbedPane inside a JFrame called BookFrame. So inside the CatalogPane, I created a JPanel called bookDisplay which displays a list of books and their details. I want it to be of size 780 by 900, leaving 20px for the scrollbar and taller than the frame so that it can scroll. Then I created a panel of size 800 by 400 because I need to leave some extra space at the bottom for other fields. I tried creating a

JPanel KeyListener Not Working

笑着哭i 提交于 2020-01-05 10:26:17
问题 import javax.swing.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; public class AnaPencere{ JFrame pen; AnaPencere(){ pen = new JFrame("Ana Pencere"); pen.setSize(613, 253); pen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pen.setLocationRelativeTo(null); pen.setResizable(false); pen.add(new Cizim()); pen.setVisible(true); } private class Cizim extends JPanel{ private Cizim() { this.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) {