JSplitPane in JFrame class
Hi all,
Sorry about the newbie question. I'm trying to place a split pane into a JFrame, but I'm not entirely clear how to implement it. The code is below. Ideally, I'd have one ImageJPanel on the left-hand side, to be populated with a BufferedImage, and one on the right, to be populated with a graphical representation of some data from that image (specifically RGB and HSV histograms). However, I'm just having trouble displaying the JSplitPane, although, admittedly, I don't know much about it. Any advice is appreciated. Thanks!
Joe
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
import java.awt.image.*;
public class ImFrame extends JFrame implements ActionListener {
ImageJPanel imgPanel = new ImageJPanel();
ImageJPanel leftPanel = new ImageJPanel();
ImageJPanel rightPanel = new ImageJPanel();
JScrollPane imageScrollPane = new JScrollPane();
JScrollPane leftPane = new JScrollPane();
JScrollPane rightPane = new JScrollPane();
private JSplitPane split;
public ImFrame(){
super("Image Display Frame");
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
JMenu fileMenu = new JMenu("File");
fileMenu.add(makeMenuItem("Open"));
fileMenu.add(makeMenuItem("Save Analysis Data"));
fileMenu.add(makeMenuItem("Quit"));
JMenu analyzeMenu = new JMenu("Analyze");
analyzeMenu.add(makeMenuItem("Smooth"));
analyzeMenu.add(makeMenuItem("Display RGB and HSV"));
analyzeMenu.add(makeMenuItem("Display Second Image for Comparison"));
JMenuBar menuBar = new JMenuBar();
menuBar.add(fileMenu);
menuBar.add(analyzeMenu);
setJMenuBar(menuBar);
split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
leftPanel, rightPanel);
split.setDividerLocation(150);
split.setSize(300, 300);
split.setRightComponent(rightPane);
split.setLeftComponent(leftPane);
setContentPane(split);
setSize(300, 300);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(imageScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(imageScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)
imageScrollPane.setViewportView(imgPanel);
pack();
//setVisible(true);
public void actionPerformed(ActionEvent e){
String command = e.getActionCommand();
if(command.equals("Quit")) System.exit(0);
else if (command.equals("Open")) loadFile();
private void loadFile(){
JFileChooser chooser = new JFileChooser();
int result = chooser.showOpenDialog(this);
if (result == JFileChooser.CANCEL_OPTION) return;
try{
File file = chooser.getSelectedFile();
System.out.println("Loading..." + file.getAbsolutePath());
BufferedImage buffImage = ImageIO.read(file);
if (buffImage != null) {
leftPanel.setImage(buffImage);
imageScrollPane.setViewportView(leftPanel);
} else {
System.out.println("Problem loading image file.");
} catch(Exception e){
System.out.println("File error:" + e);
private JMenuItem makeMenuItem(String name){
JMenuItem m = new JMenuItem(name);
m.addActionListener(this);
return m;
public static void main(String[] s){
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ImFrame().setVisible(true);
}
split.setDividerLocation(150); // only works once the GUI is visible
split.setSize(300, 300);Don't use setSize() it has no effect when using a layout manager
split.setRightComponent(rightPane);
split.setLeftComponent(leftPane);You are adding an ImagePanel. Presumably ImagePanel extends JPanel. I don't know what you code is like but I'm guessing that you are doing custom painting. When you do custom painting the panel does not have a preferred size (unless you specifically set it). So when you do a pack(), the preferred size of each panel is (0, 0) and therefore the preferred size of the split pane is (0, 0) plus the divideer size, so you frame is really small.
setContentPane(split);Just use getContentPane().add(split);
setSize(300, 300);Has no effect since the pack method will recalculate the preferred size as described above.
Here is a simple example:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SplitPaneBasic extends JFrame
JSplitPane splitPane;
public SplitPaneBasic()
JPanel red = new JPanel();
red.setBackground( Color.RED );
red.setPreferredSize( new Dimension(100, 100) );
// red.setMinimumSize( new Dimension(0, 0) );
JPanel blue = new JPanel();
blue.setBackground( Color.BLUE );
blue.setPreferredSize( new Dimension(100, 100) );
splitPane = new JSplitPane();
splitPane.setOneTouchExpandable(true);
splitPane.setLeftComponent( red );
splitPane.setRightComponent( blue );
// splitPane.setDividerLocation(1.0);
// splitPane.setResizeWeight(0.5);
getContentPane().add(splitPane, BorderLayout.CENTER);
splitPane.setDividerLocation(1.0);
public static void main(String[] args)
SplitPaneBasic frame = new SplitPaneBasic();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setLocationRelativeTo( null );
frame.splitPane.setDividerLocation(0.75);
frame.setVisible(true);
// frame.splitPane.setDividerLocation(1.0);
}
Similar Messages
-
Problem with setContentPane() in JFrame class
I recently discovered a problem with the setContentPane method in the JFrame class. When I use setContentPane(Container ..), the previously existing contentPane remains in the stack. I have tried nullifying getContentPane(), and all manner of things, but, each time I use setContentPane, I have another instance of a JPanel in the stack.
I'm using code similar to setContentPane(new CustomJPanel()); and each time the user changes screens, and a similar call to that is made, the old CustomJPanel instance remains in the stack. Can anyone suggest a way around this? On their own the panels do not take up very much memory, but after several hours of usage, they will build up.I tried what you suggested; it only resulted in a huge performance decrease. The problem with memory allocation is still there.
Here is the method I use to switch screens in my app:
public static void changeScreen (JPanel panel){
try{
appFrame.setTitle("Wordinary : \""+getTitle()+"\"");
appFrame.setContentPane(panel);
appFrame.setSize(appFrame.getContentPane().getPreferredSize());
appFrame.getContentPane().setBackground(backColour);
for (int i = 0; i < appFrame.getContentPane().getComponents().length; i++)
appFrame.getContentPane().getComponents().setForeground(textColour);
//System.out.println("Background colour set to "+backColour+" text colour set to "+textColour);
appFrame.validate();
catch (Exception e){
//System.out.println("change");
e.printStackTrace();
And it is called like this:
changeScreen(new AddWordPanel());The instantiation of the new instance is what is causing the memory problems, but I can't think of a way around it. -
Problem with JFrame class.
To risolve my problem i need for few diferent frame
( for esample in one i put JTextFild that take the user input, in a nother one i need for program output ) . But, th problem is, all my frames using the same object.
If i construct diferent JFrame window class i have problem that i don't acess in the same object from all the window. And if i dont use a object, i have static acess .
I risolve the problem with 1 JFrame class with diferent constructors, but i wont a diferent way to risolve my problem, because there are few windows.
Help me.....Make the class that extends JFrame an inner class of the the main class. You can then access all members of the outer class.
-
Doubt in processing of statements after calling JFrame class
I have two java classes.
The first one is Normal class and the second one is a JFrame class.
In the first Class, i created an object for second JFrame class followed by a set of statements.
Based on the input from the second class, i must process the statements, the problem i am facing is after creating the object for second frame class , the first class continues execution of the remaining statements. I must stop the execution of the statements until i get an input from the second class.
How can i make the first class wait for an input from the second class.
if possible provide me some source code.
Thanks for your help!.Use a modal JDialog instead of a JFrame.
db -
Creating a java thread in a jframe class?
hello is this possible to create a thread for a jframe class? so that everytime a connection is established, a new thread along with the gui is opened automaticly? if so, would i just need to insert extends Thread on my declaration of my class?
i already have this code at the top of my jframe class..
public class ChatDialog extends javax.swing.JFrame implements WindowListenerwhere and how would i implement the run() method in thsi class?
full code:
package icomm;
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class ChatDialog extends javax.swing.JFrame implements WindowListener {
protected String messege;
private Socket client_user = null;
/** Creates new form ChatDialog */
public ChatDialog()
initComponents();
addWindowListener( this );
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
convo_txt = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
txt_messege = new javax.swing.JTextArea();
send_button = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
Option = new javax.swing.JMenu();
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane1.setViewportView(convo_txt);
getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, 220, 270));
jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
txt_messege.setLineWrap(true);
jScrollPane2.setViewportView(txt_messege);
getContentPane().add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 310, 220, 70));
send_button.setText("Send");
send_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
send_buttonActionPerformed(evt);
getContentPane().add(send_button, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 390, -1, -1));
jMenu1.setText("File");
jMenuBar1.add(jMenu1);
Option.setText("Option");
jMenuBar1.add(Option);
setJMenuBar(jMenuBar1);
pack();
// </editor-fold>
private void send_buttonActionPerformed(java.awt.event.ActionEvent evt) {
//get txt from textbox
String text = txt_messege.getText();
public void windowClosing(WindowEvent e)
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e)
* @param args the command line arguments
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ChatDialog().setVisible(true);
// Variables declaration - do not modify
private javax.swing.JMenu Option;
private javax.swing.JTextArea convo_txt;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JButton send_button;
private javax.swing.JTextArea txt_messege;
// End of variables declaration
}Instead of attempting to have the frame extend thread (or implement Runnable which is actually possible since you cannot have multiple inferitance). You might want to just create the frame and have that frame lauch an associated thread to take care of the processing required.
-
How sholud we call one jframe class from another jframe class
Hi
In my application i am calling one jframe class from another jframe clas.
how sholud we make previous jframe inactve when another jframe is invoked?(user sholud not able to make any changes on on parent jframe window when another jframe is invoked)
Pls reply.Sorry for me it is not possible to change existing code,
pls suggest me any other solution so that i can inactive parent jframe when child jframe execution is going on. -
Why we extends JFrame class in java
Hello Java Developers,
I am new to Java & Currently I am trying my hands on Java Swings.
I wrote a very simple program in Java to display a JFrame on screen. My code is as follows:
import javax.swing.*;
public class JavaFrame {
public static void main(String args[]){
JFrame frame = new JFrame();
frame.setTitle("My Frame");
frame.setSize(400, 150);
frame.setLocation(300, 300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
I saw some examples on internet & they are extending "JFrame" in their every example. I want to know what is the benefit of this ??? here is code:
import javax.swing.*;
public class JavaFrame extends JFrame {
public static void main(String args[]){
JFrame frame = new JFrame();
frame.setTitle("My Frame");
frame.setSize(400, 150);
frame.setLocation(300, 300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
My second question is what is the meaning of line "frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);"
frame - This object of class created by me.
setDefaultCloseOperation() - This is predefined method in JFrame class.
JFrame.EXIT_ON_CLOSE - what is the meaning of this ??I saw in JFrame API as you suggested & I found that
EXIT_ON_CLOSE is an "public static final" method.Look again. It's not a method.
final: this mehod must be executed
am I right ???No. final means that the value cannot be reassigned.
Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
db -
Beginner question - How to use JFrame class?
How can we use a JFrame class created? Shld you run it like JApplet on browser or appletviewer?
First, if I understand what you want to do exactly, you need to write two classes. The main one will be your class that extends javax.swing.JFrame. Wherehas the second will be your "container class" and will extends java.applet.Applet. This second class will do nothing more than instantiate your JFrame subclass. This is this last class that will be called in your HTML file.
I made up some code quickly to give you an idea:
import javax.swing.JFrame;
public class TestJFrame extends JFrame {
//Constructor
public TestJFrame() {
super("My test JFrame"); //calls the superclass constructor
this.setSize(200,200);
this.setVisible(true);
// Main (optionnal here: just in case you need to
// instantiate the class within an application)
public static void main(String[] args) {
new TestJFrame();
=======================
import java.applet.Applet;
public class TestJFrameApplet extends Applet {
public void init() {
new TestJFrame();
Hope this help -
Why does the JFrame class implement the Accessible interface in its code? Isn't the Accessible interface already inherited when the JFrame extended to the Window class?
I'm fairly new to Java and have been going through the documentation on the APIs and noticed this. Haven't seen if it is elsewhere.
Thanks to whoever provides input.Because Sun do not exclusively employ perfect developers, basically. Looking at the source for both JFrame and Window, you'll see they were written by different programmers. The pair that developed JFrame possibly didn't realise that the class implicitly already implemented Accessible. Notice how Frame implements MenuContainer, which a superclass - Component - already does.
The JDK isn't a particularly well-designed lump of code, to be honest. It's full of examples of how not to do things, poor OO design and silly mistakes like this. Don't make the mistake of thinking because it's a Sun release, it must show The Right Way ? to do things, it doesn't -
Hi All,
I have a JSplitPane on which left Component is JTree and right component is multiple mini JFrames...So after adding frames on the right side i am able to drag tha frame whereever i want..If i want to restrict it only into the right window available..How can i do that??
Thanks in advance.
regards,
ViswanadhYa Camic...I got an example when i searched in google...Here it is.
import javax.swing.*;
public class DTopTest extends JFrame {
public static void main( String[] arg ) {
new DTopTest();
public DTopTest() {
JDesktopPane desktop = new JDesktopPane();
setContentPane( desktop );
JInternalFrame top = new JInternalFrame( "Top" );
top.setBounds( 10, 10, 200, 200 );
top.setVisible( true );
desktop.add( top, new Integer( 10 ) );
JInternalFrame normal1 = new JInternalFrame( "Normal 1" );
normal1.setBounds( 100, 100, 300, 300 );
normal1.setVisible( true );
desktop.add( normal1 );
JInternalFrame normal2 = new JInternalFrame( "Normal 2" );
normal2.setBounds( 300, 300, 300, 300 );
normal2.setVisible( true );
desktop.add( normal2 );
setDefaultCloseOperation( EXIT_ON_CLOSE );
setSize( 500, 500 );
setVisible( true );
private class TopFrame extends JInternalFrame {
TopFrame( String title ) {
super( title );
public boolean isSelected() {
return true;
} In this example InternalFrames are added to Main frame with the help of JDesktopPane..My question is apart from me adding JInternalFrames i will be adding some textfields or labels on the same..So i require GridLayout to be enabled for the container,but JDesktopPane doesnt support either
setLayout(new GridLayout(0,1,5,5));
or
JDesktopPane jdp=new JDesktopPane() //argument as GridLayout.So i just wanna know how to do this??
Thanks in advance.
regards,
Viswanadh -
Netbeans nightmare Converting a JFrame class to a JApplet Class
Hello im not exactly new to java but im having problems getting my applets to work when i try other peoples example applets they always work but mine never seem to. here is what i am doing i wrote a card game in VB6 long story short i completely rewrote it in java because only ie supports ActiveX.
It works awesome as a stand alone App whilst in Jframe and with a main() sub.
I tried about 15 tutorials on how to convert a jframe to a applet with no success i always got errors and applet never loaded in browser.
then i found these tips on how to do it "really easy" of course when my applet loads and im not sure it even really does i get nothing but a grey box i never seem my components a bunch of jlabels with icons loaded that look like card images it all looks great in the design tab of NetBeans. I never see any of the controls in browser. These are the links to the two tutorials that spawned my trying this. http://forums.java.net/jive/thread.jspa?threadID=57965&tstart=0 http://forums.java.net/jive/thread.jspa?threadID=57965&tstart=0
well to quote this guy it feels like its going to take 100 years to figure this out google has a million links to junk when i try searches and sun has no great help for searching either on their documentation. my program is rediculously low tech and i cant seem to get it to do anything or work at all as an applet.
my class looks like this: i removed all the constructor code as it was making post too long my applet shows up normal in the preview window of Netbenas but just a grey square of browser not sure whats wrong please someone help me.. Thanks You
import java.util.Random;
public class AcesKingsJApplet extends javax.swing.JApplet {
/** Initializes the applet AcesKingsJApplet */
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
System.out.println("InitCOmpleted");
// NewGame(1);
} catch (Exception ex) {
ex.printStackTrace();
public void TableCardClick(int arg1){
public void DiscardPileClick(int arg1){
public void PerformUndoAction(){
public void NewGame(int arg1){
//new game code here
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel16;
private javax.swing.JLabel jLabel17;
private javax.swing.JLabel jLabel18;
private javax.swing.JLabel jLabel19;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel20;
private javax.swing.JLabel jLabel21;
private javax.swing.JLabel jLabel22;
private javax.swing.JLabel jLabel23;
private javax.swing.JLabel jLabel24;
private javax.swing.JLabel jLabel25;
private javax.swing.JLabel jLabel26;
private javax.swing.JLabel jLabel27;
private javax.swing.JLabel jLabel28;
private javax.swing.JLabel jLabel29;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel30;
private javax.swing.JLabel jLabel31;
private javax.swing.JLabel jLabel32;
private javax.swing.JLabel jLabel33;
private javax.swing.JLabel jLabel34;
private javax.swing.JLabel jLabel35;
private javax.swing.JLabel jLabel36;
private javax.swing.JLabel jLabel37;
private javax.swing.JLabel jLabel38;
private javax.swing.JLabel jLabel39;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel40;
private javax.swing.JLabel jLabel41;
private javax.swing.JLabel jLabel42;
private javax.swing.JLabel jLabel43;
private javax.swing.JLabel jLabel44;
private javax.swing.JLabel jLabel45;
private javax.swing.JLabel jLabel46;
private javax.swing.JLabel jLabel47;
private javax.swing.JLabel jLabel48;
private javax.swing.JLabel jLabel49;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel50;
private javax.swing.JLabel jLabel51;
private javax.swing.JLabel jLabel52;
private javax.swing.JLabel jLabel53;
private javax.swing.JLabel jLabel54;
private javax.swing.JLabel jLabel55;
private javax.swing.JLabel jLabel56;
private javax.swing.JLabel jLabel58;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel60;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
// End of variables declaration
int tableCardIndex = 99; //array only cause it has to be or game fails
int discardPileIndex = 99;
int[] cardDeckArray = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54};
int[] cardDeckArrayPlayed = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
//int[] precheckarg1;
boolean GoAheadWithPlay;
int gameUndoCount;
int gamePlayCount;
int gameCurrentRound = 1;
int cardPointValue;
int discardCardValue;
int tableCardValue;
int tableCardsRemaining = 35;
int discardPileCards;
int currentDiscardPileCard;
int playerScore;
// loss checking variables
int badPlaysCount = 0;
// variables for undo related activity below
int[] undogamePlayCount = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int[] undodiscardPileCards = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int[] undocurrentDiscardPileCard = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int[] undoMethod = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int[] undoTableCard ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int[] undoDiscardCard ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
//end undo variable collection
}You shouldn't start a new thread when you've already created a recent one with the exact same subject matter:
[http://forums.sun.com/thread.jspa?threadID=5447497|http://forums.sun.com/thread.jspa?threadID=5447497]
And my advice in the previous thread still stands. Put your program in a JPanel so it's environment-agnostic, then create two wrappers for standalone apps and applets.
(or just use Java Web Start)
Also your program has all sorts of other problems. This is terrible coding:
private javax.swing.JLabel jLabel37;If you need lots of labels that all have the same meaning, put them in a collection. Give things meaningful names. etc.
If that code was generated by Netbeans....then this is an example why you shouldn't use code generation tools... -
Best way to repaint/refresh JFrame classes.
Hello everyone,
I am developing a small application for my studies. I have several classes many representing a user form allowing interaction with my system.
One of my first class instances is a Menu Screen from which the user can for example update their details. When the Update Details frame is closed by the user I invoke
frameName.setVisible(false);
frameName.dispose();This removes the Update Details frame and the Menu Screen is now fully visible.
However this screen does not get refreshed and remains partially obscured by the background color of the JFrame, even if I bring say a browser to the foreground and then click the original Menu Screen to the foreground it does not refresh the Menu Screen and remains half painted.
I was wondering about a few things.
1. Is there a way of detecting when the current JFrame has just received the focus, at which point I could repaint the screen.
2. Is there a way of Menu Screen discussed above being able to detect the closure of the Update Details JFrame (a separate class) and then take appropriate steps to repaint/refresh itself.
3. Ideally what I would like to do is Hide the Menu Screen then allow the user to interact with their menu selection and then Un-hide the Meun Screen when the user is done interacting with their menu selection.
4. Are there any tutorials on this type of thing, that anynone could direct me to.
Thank you for your consideration.
Cheers
MarkHello everyone,
I am developing a small application for my studies. I
have several classes many representing a user form
allowing interaction with my system.
One of my first class instances is a Menu Screen from
which the user can for example update their details.
When the Update Details frame is closed by the user I
invoke
frameName.setVisible(false);
frameName.dispose();This removes the Update Details frame and the Menu
Screen is now fully visible.
However this screen does not get refreshed and remains
partially obscured by the background color of the
JFrame, even if I bring say a browser to the
foreground and then click the original Menu Screen to
the foreground it does not refresh the Menu Screen and
remains half painted.
I was wondering about a few things.
1. Is there a way of detecting when the current JFrame
has just received the focus, at which point I could
repaint the screen.
2. Is there a way of Menu Screen discussed above being
able to detect the closure of the Update Details
JFrame (a separate class) and then take appropriate
steps to repaint/refresh itself.
3. Ideally what I would like to do is Hide the Menu
Screen then allow the user to interact with their menu
selection and then Un-hide the Meun Screen when the
user is done interacting with their menu selection.
4. Are there any tutorials on this type of thing, that
anynone could direct me to.
Thank you for your consideration.
Cheers
Mark -
Using getContentPane() in JFrame class
Hello,
I'm reading Bruce Eckel's book.
In chaapter 14, I read TextArea.java.
My question is:
What is the purpose of getContentPane() in the constructor TextArea() in the code below ?
Isn't JFrame IS a Container ? why bother to get another Container ?
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
import com.bruceeckel.swing.*;
import com.bruceeckel.util.*;
public class TextArea extends JFrame {
private JButton
b = new JButton("Add Data"),
c = new JButton("Clear Data");
private JTextArea t = new JTextArea(20, 40);
private Map m = new HashMap();
public TextArea() {
// Use up all the data:
Collections2.fill(m, Collections2.geography,
CountryCapitals.pairs.length);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Iterator it = m.entrySet().iterator();
while(it.hasNext()) {
Map.Entry me = (Map.Entry)(it.next());
t.append(me.getKey() + ": "+ me.getValue()+"\n");
c.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
t.setText("");
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
cp.add(new JScrollPane(t));
cp.add(b);
cp.add(c);
public static void main(String[] args) {
Consoleb.run(new TextArea(), 475, 425);
}I appreciate the reply.
There are endless API to read.
I found this:
For conveniance JFrame, JDialog, JWindow, JApplet and
JInternalFrame, by default, forward, by default, all
calls to the add, remove and setLayout methods, to
the contentPane. This means you can call:
rootPaneContainer.add(component);That was introduced in 1.5. May people still use older versions of Java, so use that add method with caution. I myself see no reason to use it, since it is a bit of a hack.
Another question on the side:
How can I remove a topic that I created ?Like karma, no thread ever goes away :-) -
Importing existing JFrame class into a new Java Studio Enterprise 8 project
I have taken over the re-development of some old code, and have imported it into the Java Studio IDE. However, the help files seem to indicate that I cannot use the Form Editor to make changes to the existing JFrame object. It can only be used if you created the object from within the Studio.
Is this correct? If so, has anyone devised a reasonable work-around besides manually making the changes? (The biggest problem with this approach is that they don't seem to appear in the Form Editor; I would have to make the changes there manually too). The GUI is somewhat complex, and would be a real pain to recreate from scratch.
Any help is greatly appreciated.
~BrianThe following is a FAQ item on generating form files from existing class files:
http://www.netbeans.org/kb/faqs/gui-editor.html#FaqFormGeneratingFormFile
Can I generate the .form file for an existing class?
Unfortunately no.
NetBeans form editor is not able to regenerate a missing .form file for GUI classes, or to generate a .form file for GUI classes not originally created in NetBeans.
However, there are some external tools trying to address this problem, e.g. FormGenerator.
There are two such utilities available at:
http://contrib.netbeans.org/servlets/ProjectDocumentList
( FormGenerator.zip and FormGenerator2.zip ).
You may want o backup existing .form files, generate new ones from the classes with either of the above utilities and then compare the two versions.
Ref: http://swforum.sun.com/jive/thread.jspa?forumID=122&threadID=59475 -
Passing variables among Jframe classes
I have 2 Jframes and i want one frame to read a variable in the other frame..
How can i do that?It's better practice, really, handle the data from a frame in a more abstracted form, and keep the details of the form elements etc. within the extended frame object.
Say, for instance, one frame has a text account number field then.
public class AccountFrame extends JFrame {
private JTextField accountField;
public String getAccountNumber() {
return accountField.getText();
public String setAccountNumber(String newAccount) {
accountField.setText(newAccount);
...Where there's a whole bunch of fields, then you should consider a "data transfer object", a separate class, usually a bean, which holds the values from the frame as Strings etc..
Maybe you are looking for
-
If-statement in application-process
Hi, First I will tell you which APEX I am using: 3.0.1 Ok, I have got a form where there are 4 fields: P13_ACCTNO (Popup LOV (fetches first rowset)), P13_LOCATION_NAME(Text Field (Disabled, saves state)), P13_COMP_ACCTNO( Popup LOV (fetches first row
-
Error: failed to prepare transaction (could not satisfy dependencies)
Hi, I was going to install a winff package (a GUI front end to ffmpeg for converting between video formats), but when I ran yaourt -S winff and tried to install it refused because it isn't for the x86_64 architecture. So I decided to edit the PKGBUIL
-
Problem using email to upload image files to Mobile Me gallery
I will cross post this question to both Mail and Mobile Me discussion groups because I don't know where my problem lies. I have published a gallery page from iPhoto to my Mobile Me gallery. There are two ways to upload additional photos. I am not hav
-
Column name of custom columns is possible of translating automatic
In SharePoint 2013 is possible of translating automatic the column name of custom columns with machine translation services or it is necessary create resource files or source site and target site?
-
Using 9500 to access internet with laptop
I have a basic laptop that is not connected to the internet. Is it possible to use the 9500 to connect my laptop to the internet.