Swing/AWT/SWT :: Unable To Add Jpanel Dynamically Inside Single Frame
Oct 4, 2014
I am building a GUI application which consists of two panels "panel" and "panel1". "panel1" have a button "addTimer" when clicked it should add the "panel" to the frame if i gain click the button it should again add the "panel" without overlapping the previous "panel" rather it should be created below the previous "panel". If i click on the button "addTimer" n times it should add the panel n times. Along with this the frame size has to dynamically change depending on the number of panels produced. Below is the code i tried my level best to satisfy the above conditions.
package superTimerV2;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SuperTimer extends JFrame {
private static final long serialVersionUID = 1L;
[Code] ....
View Replies
ADVERTISEMENT
Jun 20, 2014
Am trying to add buttons dynamically in a new Jpanel on click of a button. i am getting new Jpanel but not able to see the buttons.
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if((!(playerFirst.getText().equalsIgnoreCase("") ||playerSecond.getText().equalsIgnoreCase(""))&&(!playerFirst.getText().equalsIgnoreCase(playerSecond.getText())) ) ){
//unoGameController.playGame(playerFirst.getText(), playerSecond.getText());
CardLayout cardLayout=(CardLayout)(frmUno.getContentPane().getLayout());
[Code]...
prepareHandsForGuiCode is
public UNODeckMain prepareHandsForGui(UNODeckMain unoDeckMain){
JButton[] btnArr =new JButton[50];
for(int i=0;i<50;i++){
btnArr[i]=new JButton("hi");
panel_player1.add(btnArr[i]);
}return unoDeckMain; }
Am i skipping something ?
View Replies
View Related
Apr 22, 2014
I have a Single Frame Application and I simply want to prompt the user with a dialog confirming they really want to close before they actually close the program, specifically when they click the X in the upper right. I THOUGHT it was like any other java application, with the slight added complexity of having to target the program-created-JFrame with: ".getApplication().getMainFrame()".
MyApp.getApplication().getMainFrame().setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
With that code, DO_NOTHING_ON_CLOSE is set on the JFrame, yet the program closes anyways. Which I don't understand.So I did some reading and found this: URL....That lead me to the configureWindow override, where I successfully tried this:
root.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// write your code here
System.out.println("Window Closing");
}
});
But as far as I can tell that will only let me react to the window closing, not to the command to close it, where I could then kill the command in the dialog if they so "no I'm not ready to quit yet", if that makes sense. So, how to give a prompt before closing?I am using netbeans IDE to create this app - not sure if that is relevant, since maybe it is an oddity with the IDE and not Single Frame Applications.
View Replies
View Related
Feb 3, 2014
I am writing a ComputerBaseTest application with Netbeans. I have each question on a panel and I want the questions(panels) to be switched, viewing the previous and the next question on a single frame, but I do not know how.
I only understand frame switching if each questn is to be on a frame but each score on each question (frame) do not sum up to give the overall score at the end of the test. Using multi-frame shows a sign of bad programming.
View Replies
View Related
Apr 9, 2014
I have a Jframe and i want to add inside 4 different jpanel.This is easy.
what is difficult is how can i change them dynamically with 4 other new jpanels and 4 other new jpanels?
I have try with BorderLayout but not working.
It's a wizard like but not the same.
I have a jpanel with jbuttons jpanel with a jtable jpanel with textarea and jpanel with jlabels. All this have to change with other 4 jpanels, where to look?
View Replies
View Related
Feb 9, 2015
In the method mouseClicked(MouseEvent me) the co-ords of the click are obtained.
* if they are within the confines of the rectangle rect, console output System.out.println("inside box") is displayed
* in either case the click co-ords are displayed in the console
I'm getting the co-ords of the mouse clicks but no message when the click is inside the box
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/*
Experiment 04 was successful. So now (Experiment 05) I must try and see if I can identify mouse clicks that occur within the rectangle.
*/
public class AFrame extends Frame implements MouseListener {
ARectangle rect;
public AFrame(ARectangle rect) {
[Code] ....
View Replies
View Related
Apr 22, 2014
I want to calculate the height of a dialog that contain only a table depending on how many rows that table it has so I'm using the cross multiplication rule.For example i check initially that my table is well fitting into the dialog(Without space at the bottom) for some value and after that i use the cross multiplication rule because data are dynamic.But unfortunately this rule does not solve the problem.What's the best rule for fitting a dynamic table inside a dialog or a frame? Here is my code.
public class FlowLayoutChangingGap {
public static void main(String[] args) {
// just for testing perpose but data are getting from database and it's dynamic
Object[][] data = {
{ "Kathy", "Smith", "Snowboarding", new Integer(5) },
{ "John", "Doe", "Rowing", new Integer(3) },
[Code] ....
View Replies
View Related
Apr 3, 2014
i want to know how i can add more than one frame in a single frame means main window or frame will be constant and only components will be chang or vary as in a software or game .
View Replies
View Related
Apr 15, 2014
Title says it all i want to get these two components:
Java Code:
package TestVersion;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JPanel;
public class GameWorld extends JPanel {
private int charX = 225;
private int charY = 225;
private int charDiameter = 25;
[code]...
View Replies
View Related
Apr 14, 2015
I've been trying to draw a panel on a frame with simple drawString drawRect and oval but when i run it the frame shows up with the exit on close stuff but nothing will show inside . this is my code :
import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.JFrame;
class Draw extends JPanel{
public void paintcomponents(Graphics g){
super.paintComponent(g);
g.drawLine(10,15,20,30);
[Code] .....
I'm not sure what's wrong , probably something to do from this pc ? since in the lab work at uni it worked fine .
View Replies
View Related
Feb 7, 2014
I am trying to place a number of JLabel and JTextField objects inside a JPanel which has a JScrollPane.
One thing is, that at one time, I have have a certain number of JLabel and JTextField objects which number would cover an area greater than the JPanel's vertical size.
How when I implement the JScrollPane and I run the program, the scroll bars appear, but they don't scroll the pane inside the JPanel, the items are fixed.
Could the problem be because I am using a Null Layout.
Will I have to use one of the standard layouts available, like GridLayout for the JScrollPane scrolling function to work?
View Replies
View Related
Sep 15, 2014
I am trying to play video in JPanel using vlcj in ubuntu, there is no error. My project builts successfully. but do not plays video. when i run code JFrame comes for a while. when i use same code in windows. it plays video and works successfully, but not in ubuntu.
In output window , it show following
A fatal error has occured in java runtime environment. (and so many things.)
Following is my code : (i am using vlcj-3.0.1)
import com.sun.jna.NativeLibrary;
import java.awt.BorderLayout;
import java.io.File;
import javax.swing.JFrame;
import javax.swing.JPanel;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
[Code] ...
Which path to give for vlc player in ubuntu. there are more than 5 folders with name vlc. one is in /usr/share/ and other is in /etc/ and so on.
View Replies
View Related
Sep 25, 2014
I am unable to clear disappear the background of .png image added in a translucent JPanel. I have tried it using JLabel but the image added is with white background. How can i get rid of this white background...
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class HomePage
{
JFrame frame;
JPanel pnl1, pnl2, pnl3;
JLabel lbl;
[Code] .....
View Replies
View Related
Apr 22, 2015
How to create object for "class B" and call the "function_B" from other different class D where class D has no connection with class A? Here is my program.
public class A(){
void print(){}
}
class B{
void function_B(){}
}
class C{
void function_C(){}
}
Here, A, B, C are in the same package. But class D is in different package.
View Replies
View Related
Mar 5, 2015
i want to draw a circle inside a circle in java. so far i'm using this piece of code
private Ellipse2D.Float drawEllipse(int x1, int y1, int x2, int y2) {
int x = Math.min(x1, x2);
int y = Math.min(y1, y2);
int width = Math.abs(x1 - x2);
int height = Math.abs(y1 - y2);
return new Ellipse2D.Float(x, y, width, height);
}
View Replies
View Related
Aug 19, 2014
I can't figure out how to place a JPanel from a class(Game) in to a another class(Core). I have bean stuck on this for about three days now I bean doing my research but no luck so now I think I should ask directly so here I am. Now to state clearly I am trying to place a JPanel named Game_Screen witch is in another class named Game into a JFrame named frame witch is in a another class named Core.
Now both of this classes are with in the same package and my IDE Is Eclipse.The JPanel Game_Screen has other swing pieces attached to it that should also be added with the panel on to the frame.But the change is screen should only happen when I click the buttons New Legend(N),Load Legend(L),Help(H) what already happens is that when you click any of this buttons menu.setVisible(false); is activated making everything on screen at the time disappear from the screen but the panel does not a pear.
Here's my code:
//Class - Core-------
package Source;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Core {
static Game GG = new Game();
public static void main(String[] args) {
JFrame frame = new JFrame();
[Code]...
View Replies
View Related
Dec 5, 2014
I am using a HashMap to store names (keys) and IDs (values). I have set it up so that the radio buttons are added to the JPanel dynamically. That is, each time a name/id is added, a new radio button is automatically generated and added to the panel. Here is a snippet of the code I have thus far:
private void employeeButtons() {
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(5,2,5,5));
empMap.put("Kyle", "1090");
empMap.put("Alex", "6490");
empMap.put("Mark", "9090");
empMap.put("Anne", "4390");
[code]...
The above code adds all of the radio buttons to the panel just fine. However, I need the buttons to be mutually exclusive. I would like to be able to not only add the buttons dynamically, but I need the buttons to be added to a ButtonGroup dynamically as well. That is, when I add a new hashmap entry the a new radio button is generated and added to the radiobutton group.
View Replies
View Related
Nov 18, 2014
why JLabel setText method is not setting up the text dynamically even though i am calling repaint() once i set the text? Code snippet is below
Locale currentLocale = new Locale(panel.getCountryLocal(), panel.getCountry());
ResourceBundle messages = ResourceBundle.getBundle(Constants.messageBundle, currentLocale);
messages = Panel.getMessages();
String displayString = messages.getString("101022");
[code]....
View Replies
View Related
May 5, 2015
I'm very new to Java, and I am creating a program that takes multiple user input to create one face. I have a class for the eyes, nose, lips, and headshape. For some reason, my program is not drawing the graphics. ***for question purposes, I have only included my head shape class and my test class****
my "test" class:
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class FaceTest
{
public static void main(String[] args)
{
String head = JOptionPane.showInputDialog("Would you like a circle, square, rectangle shaped head?: ");
[Code] ....
View Replies
View Related
Jan 27, 2015
I am trying to print a loop inside an array of a greater size than the loop itself. Like for example I have an array of size 7 but it has only 3 elements.
int[] array=new int[7]
array[0]=2;
array[1]=3;
array[2]=4;
now what I want to do is print these three numbers in a loop so that my array[3]=2;array[4]=3;array[5]=4 ...... till the last one. Also the array could be any size and not just 7.
View Replies
View Related
Nov 30, 2014
I wrote the following code to get a frame,button in south and a red color circle,which i got.In the "actionPerformed" method i wrote "setContentPane(mp2)" thinking it would put another panel on the frame with a blue circle but when i pushed the button,the button got stuck and the circled did not change.
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Fra implements ActionListener
{
MyPanel2 mp2;
JFrame frame;
JButton button;
public static void main(String[] args)
[Code] .....
View Replies
View Related
Mar 8, 2015
I simply want to paint an image on my frame, just once each time the paint() method is called, but how to call the paint method in any good way. This is how it looks:
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
[Code] ....
I have a frame in another class, and from my assumption I need to somehow tell my paint method to paint on that specific frame right?
View Replies
View Related
Jul 5, 2014
i have problem with the following two java classes, driver class Reservations and Room class. When i run, it just show blank frame, tell me where i gone wrong.
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
public class Reservations extends Frame implements ActionListener {
Color lightRed=new Color(255,90,90);
Color lightGreen=new Color(140,215,40);
Rooms room=new Rooms(5,3);
[code]...
View Replies
View Related
Jul 28, 2014
I am trying to call another swing frame from my current frame. And after calling second frame i dispose the current frame.
But while second frame coming on the screen, current frame gets dispose and second frame takes some seconds to appear on screen.
So its creating a bad flickering effect on screen and its not suitable for my application.
I want that first frame will call sencond frame and it will not look like second frame is called. I just want to cancel flickering effect.
Here is my source code.
1st Frame:
public class Welcome extends JFrame {
JFrame f;
JTextArea nameField,nameField1;
JLabel lable;
[Code] .....
View Replies
View Related
Jun 24, 2014
I am in the progress of updating my code and re-testing after switching from Java 6 to Java 7. When I open multiple JInternalFrames in my application under java 6 I am used to closing the top most internal frame and having the frame immediately under it become the next active frame. When I run the same code under Java 7 I see a different behaviour in as much as when I close the last frame I opened, the next one to become active is the first one.
To illustrate this another way, lets say I open 5 internal frames, 1,2,3,4 & 5
In java 6 when I close frame 5, frame 4 becomes the active frame.
In java 7 when I close frame 5, frame 1 becomes the active frame.
View Replies
View Related
Sep 25, 2014
I have been doing a project of ERP solution using JAVA AWT FRAMES and MYSQL(for database purpose). Here there is an ADMIN portion, who has the authority to make PAYROLLS of individual employees. There is a Frame where individual employee details will be shown(like basic salary, HRA, no.of leaves, other allowances...etc) in text boxes.
Now what i want is to make a PDF file of that payroll, so that I can make a hardcopy of it. The idea is just like anyother online form fill-up, where at the end you submit and save (or export) as a PDF (or text file) document. But I mention that it is a stanalone project, not an online one (i think it doesn't matter though).
So the basic idea is how to make a PDF file by extracting the text field or choice contents from a frame in JAVA AWT.
View Replies
View Related