jpanel

Space button size on my layout keyboard won't resize

…衆ロ難τιáo~ 提交于 2019-11-28 12:53:31
I am working on a typing app which includes the a keyboard but I have found a bit hard to re-size the space button to make it wider than the other buttons.. This is the way I am displaying and organizing my layout.. I can resize the whole buttons but its NOT what I want.. the whole point is to be resize just the space bar.. :) import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.util.Arrays; import

Java JPanel getGraphics()

喜夏-厌秋 提交于 2019-11-28 12:30:28
Since Java only supports single inheritance , I desire to paint directly on an instance of a JPanel that is a member of the class Panel . I grab an instance of Graphics from the member and then paint whatever I desire onto it. How can I not inherit from JComponent or JPanel and still utilize getGraphics() for painting on this without overriding public void paintComponent(Graphics g) ? private class Panel { private JPanel panel; private Grahics g; public Panel() { panel = new JPanel(); } public void draw() { g = panel.getGraphics(); g.setColor(Color.CYAN); g.draw(Some Component); panel.repaint(

Width and height of a JPanel are 0 (Specific Situation)

↘锁芯ラ 提交于 2019-11-28 12:15:31
问题 Please pardon me if this is hard to follow, but I have a specific problem that I need help solving. I have done a ton of research, and I have tried numerous solutions but none of them are working. My issue is that I have an ImagePanel class that is extending JPanel (code below), this class needs to use width and height to scale images (I am making a program where users can create custom tutorials including images). When I instantiate this I get an error saying that the width and height must

JButton are on JPanel on which it isn't should be [closed]

本小妞迷上赌 提交于 2019-11-28 12:14:42
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Hi this is my concrete problem. I was tried to add one button to one panel with for loop. This is for loop for creating JButtons. nizButtona=new JButton[22]; for(int i=0;i<nizButtona.length;i++){ nizButtona[i] = new JButton(); if(i==0){ nizButtona[i].setText("Započni kviz"); //Start quiz nizButtona[i]

Clear portion of graphics with underlying image

你离开我真会死。 提交于 2019-11-28 11:43:11
问题 I'm making a 'game' of sorts where the player has to click on an image bouncing around the screen. The catch is that the screen is in darkness and the mouse cursor is a 'flashlight' which 'light up' a small circle around it. I have a JFrame in one class consisting of: public class GameFrame { public static void main(String[] args) throws IOException { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); JFrame jf = new JFrame("Flashlight Game"); jf.setVisible(true); jf

How to get the color of a point in a JPanel? [closed]

血红的双手。 提交于 2019-11-28 11:31:22
By knowing the coordinates of a point in a JPanel, how can I get its color? Draw the content of the panel inside a Graphics2D object created from a BufferedImage and then retrieve the pixel color: BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D g2 = image.createGraphics(); _mainPanel.paint(g2); image.getColorModel().getRGB(pixel); g2.dispose(); 来源: https://stackoverflow.com/questions/13307962/how-to-get-the-color-of-a-point-in-a-jpanel

Changing and Updating JPanel Components externally, from JFrame is not Working, Swing

时光怂恿深爱的人放手 提交于 2019-11-28 11:09:26
问题 I was working with JPanel (Changing its component), but I want to change it from External JFrame. Sorry, I make this code with Netbeans (I know it put some stuff not needed for this question) and try to clean editing it, because the real code it is more large Here the code of the JPanel, with name 'MyPanel'. public class MyPanel extends javax.swing.JPanel { private javax.swing.JButton filling = new javax.swing.JButton(); private javax.swing.JScrollPane jScrollPane1 = new javax.swing

I can't get my JTable to show anything

孤人 提交于 2019-11-28 10:58:29
问题 I cant get my gui to show the Jtable, why i dont know and i dont get any error and when i print something to the screen i get 9 colum. so i get data. but what i'm doing wrong i have no idea about that. My GUIOdreHandler looks like this public GUIOrdreHandler(){ KaldSQL ks = new KaldSQL(); ResultSet rs; } public static DefaultTableModel buildTableModel(ResultSet rs) throws SQLException { java.sql.ResultSetMetaData metaData = rs.getMetaData(); // names of columns Vector<String> columnNames =

Dynamically adding components to JPanel

被刻印的时光 ゝ 提交于 2019-11-28 10:50:46
问题 I'm trying to dynamically add some components to a JPanel, but unfortunatelly they don't appear. I only see the ones added in the constuctor. Updated version (adding a new JPanel, where all the components will be): public class View extends JPanel { JPanel panel = new JPanel(); JLabel label; JLabel labels[]; JButton b1 = new JButton("OK"); public View() { this.setLayout(new FlowLayout()); this.add(panel); // adding a new JPanel label = new JLabel("My label"); panel.add(label); // adding label

Can't repaint my JFrame/JPanel

断了今生、忘了曾经 提交于 2019-11-28 10:23:37
问题 I have created a program that just moves a ball across a screen. I used to have it all in one class, but decided that it looked too messy so I split it up into three different classes: Main... initializes everything, Game... which paints everything and is a JPanel, and AL which is a KeyListener (which is also where the problem is). The problem is that I can't get the program to repaint from my AL class no matter what I try to pass into it. Can anyone help with this? Here are my three classes: