jpanel

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

孤街浪徒 提交于 2019-11-29 18:01:24
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].addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e){ cl.next(nizPanela[1]); } }); }else if(i==1){ nizButtona[i].setText("Izlaz"); //Quit nizButtona[i].addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e){ System.exit

get width and height of JPanel outside of the class

一笑奈何 提交于 2019-11-29 17:42:43
So I created a simple simple simulation where squares are spawned randomly with random vectors and bounce of the edges of the window. I wanted it to take into account the window being resized. So that if I change the dimensions of the window from 600x600 to 1200x600 the squares will bounce of the new border rather than 600x600. I tried doing getWidth() getHeight() but it would return 0. So I put it in the pain() (since it gets called on window resize) method and saved the return values as local variables. But I cannot call getjpWidth() from the Rect class. So basically what I need is to get

Can't repaint my JFrame/JPanel

痴心易碎 提交于 2019-11-29 17:29:10
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: import java.awt.Color; import javax.swing.JFrame; public class Main { static Game game; static JFrame

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

杀马特。学长 韩版系。学妹 提交于 2019-11-29 17:13:20
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.JScrollPane(); private javax.swing.JTable myTable = new javax.swing.JTable(); private final javax.swing.table

Scrollable JPanel

試著忘記壹切 提交于 2019-11-29 17:03:57
问题 How to make a JPanel scrollable? I implemented the scrollable interface yet when adding it to the containing panel with tabbedPane.add("Editor", new JScrollPane(storeyEditor = new MNScrollablePanel())); nothing works Code: public class MNScrollablePanel extends JPanel implements Scrollable { public Dimension getPreferredScrollableViewportSize() { return getPreferredSize(); } public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { return 10; } public

I can't get my JTable to show anything

落花浮王杯 提交于 2019-11-29 16:48:23
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 = new Vector<String>(); int columnCount = metaData.getColumnCount(); for (int column = 1; column <=

Disposing JFrame by clicking from an inner JPanel

♀尐吖头ヾ 提交于 2019-11-29 16:25:45
I'm trying to dispose my JFrame by clicking a button, located on a JPanel that is placed on the JFrame that I want to close. I tried to make a static method on the JFrame class, but ofcourse my IDE told me that wasn't going to happen. Anyone thinking of a solution? Thanks! Try this: public class DisposeJFrame extends JFrame{ JPanel panel = new JPanel(); JButton button = new JButton("Dispose JFrame"); public DisposeJFrame(){ super(); setTitle("Hi"); panel.add(button); add(panel); pack(); button.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) {

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

落爺英雄遲暮 提交于 2019-11-29 16:25:21
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; static Panel3 p3; public static void main(String[] args) { initFrame(); } public static void initFrame()

Update normal distribution graph using JTextField in JFreeChart

六眼飞鱼酱① 提交于 2019-11-29 16:18:45
I have a class that extends JPanel for JFreeChart . Inside of setMean() , I tried updating values of dataset or just the Function2D , but nothing changes on the graph even with repaint() . public class JFreeChartPanel extends JPanel { Function2D normal = new NormalDistributionFunction2D(0.0, 3.0); XYDataset dataset = DatasetUtilities.sampleFunction2D(normal, -5.0, 5.0, 100, "Normal"); double mean = 0.0, std = 1.0; public double getMean() { return mean; } public void setMean(double mean) { this.mean = mean; normal = new NormalDistributionFunction2D(mean,std); dataset = DatasetUtilities

Java - repainting JPanel gives an error

夙愿已清 提交于 2019-11-29 16:15:26
I'm a beginner in Java, and I'm trying to create an application that draws a rectangle where ever the cursor is located. I've already done everything, but I can't get the mouseMoved(MouseEvent) method to repaint the JPanel . Without the repaint, the rectangle is only drawn once and that's it. With the repaint, it compiles fine, but when I run it, every time the mouse is moved, I get this big " Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException " error. So, can anyone please help me out on this? import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax