Hi everybody,
I'm working on a project and basically I've developed a swing GUI
using NetBeans Swing GUI builder. On one form, I have an existing
JPanel that contains no other components. Also on this form, I have a
button that when pressed executes a function of another Class that
creates a graph (using jFreeChart) and returns the graph on a JPanel.
My question is: Is it possible to replace the existing JPanel on the
aforementioned form with the JPanel returned from the graphing method
such that I can dynamically place the created graph on the form?
I'm not sure exactly how to go about doing this. I know that I can
take the JPanel containing the graph and show it on another frame by
creating and new frame and showing it. However my desire is to have
the graph be part of the existing form in the location where the
existing JPanel lies.
Any help would be very much appreciated.
Thanks.
Brian
|
|
0
|
|
|
|
Reply
|
Brian
|
3/11/2008 4:23:49 AM |
|
On Mar 11, 3:23=A0pm, Brian <bce...@gmail.com> wrote:
> Sub: Replacing an existing jPanel with a new jPanel
There is no such class in the J2SE as jPanel.
Did you mean JPanel?
=2E..
> I'm working on a project and basically I've developed a swing GUI
> using NetBeans Swing GUI builder.
That does not bode well. GUI builders
generally produce crap code unless the
person using them already understands
component layout. *
>..=A0On one form,
What is a 'form'? Please quote actual class names.
>...I have an existing
> JPanel that contains no other components. =A0Also on this form, I have a
> button that when pressed executes a function of another Class that
> creates a graph (using jFreeChart) and returns the graph on a JPanel.
> My question is: =A0Is it possible to replace the existing JPanel on the
> aforementioned form with the JPanel returned from the graphing method
> such that I can dynamically place the created graph on the form?
Sure.
- A CardLayout can contain both components
and flip between them.
- The code might remove the original JPanel,
add the new JPanel, then validate() the JFrame.
- If it makes any sense, you might also use a
JTabbedPane and add the new JPanel to a new tab.
* Start here..
<http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html>
--
Andrew T.
PhySci.org
|
|
0
|
|
|
|
Reply
|
Andrew
|
3/11/2008 4:51:38 AM
|
|
Brian wrote:
> Hi everybody,
>
> I'm working on a project and basically I've developed a swing GUI
> using NetBeans Swing GUI builder. On one form, I have an existing
> JPanel that contains no other components. Also on this form, I have a
> button that when pressed executes a function of another Class that
> creates a graph (using jFreeChart) and returns the graph on a JPanel.
> My question is: Is it possible to replace the existing JPanel on the
> aforementioned form with the JPanel returned from the graphing method
> such that I can dynamically place the created graph on the form?
>
> I'm not sure exactly how to go about doing this. I know that I can
> take the JPanel containing the graph and show it on another frame by
> creating and new frame and showing it. However my desire is to have
> the graph be part of the existing form in the location where the
> existing JPanel lies.
>
> Any help would be very much appreciated.
>
> Thanks.
>
> Brian
You've got a couple of options. You can remove the first JPanel and add
the second or you could just add the second to the first.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class test7 {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel p1 = new JPanel();
p1.setBackground(Color.BLUE);
p1.setPreferredSize(new Dimension(640,480));
p1.setLayout(new GridBagLayout());
f.add(p1,BorderLayout.CENTER);
final JPanel p2 = new JPanel();
p2.setBackground(Color.GREEN);
p2.setPreferredSize(new Dimension(400,300));
JButton b = new JButton("Add Green Panel");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
p1.add(p2);
p1.validate();
p1.repaint();
}
});
f.add(b,BorderLayout.NORTH);
b = new JButton("Remove Green Panel");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
p1.remove(p2);
p1.validate();
p1.repaint();
}
});
f.add(b,BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}
});
}
}
--
Knute Johnson
email s/nospam/linux/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
|
|
0
|
|
|
|
Reply
|
Knute
|
3/11/2008 4:55:43 AM
|
|
|
2 Replies
496 Views
(page loaded in 0.076 seconds)
Similiar Articles: Replacing an existing jPanel with a new jPanel - comp.lang.java ...Hi everybody, I'm working on a project and basically I've developed a swing GUI using NetBeans Swing GUI builder. On one form, I have an existing JPanel that contains ... Correct "Dispose" of junk JPanel (not JFrame) - comp.lang.java.gui ...Replacing an existing jPanel with a new jPanel - comp.lang.java ... Correct "Dispose" of junk JPanel (not JFrame) - comp.lang.java.gui ... I want to replace a panel of ... JPanel in JTable cell - comp.lang.java.guiSo you can just replace Jtable with QuickTable. For example, we create a File selector cell using a JPanel and JButton. ... CellComponent { JLabel jl = new ... How to send mouse event to another component? - comp.lang.java.gui ...Hi, I have built a JPanel with lots of other small ... -- "TFritsch$t-online:de".replace(':','.').replace ... Class creates a new frame. ... > =A0 Don't call ... JTextPane, JEditorPane, copy & paste etc. - comp.lang.java.gui ...... app that lets you change the text display style (font, color etc.) for new and existing ... soft-sys.matlab How to clear JPanel? - comp.lang.java.gui How to clear JPanel ... Graphics.drawImage function not working, please help. - comp.lang ...> public void paint(Graphics g) (please replace tabs with 2 ... I realized that I was extending Panel rather than JPanel ... JavaTest extends JApplet { Picture picTest = new ... revalidate() vs. repaint()? - comp.lang.java.gui... Stack Overflow I'm putting together a Swing application where I often want to replace the contents of a JPanel. To do this, I'm calling removeAll(), then adding my new ... Howto: Simulate a close (X) button in an applications toolbar ...... frame along with a caption/title bar, which does not fit well within an existing ... Open new JPanel (JFrame, ...) by clicking JButton - comp.lang.java ... Howto: Simulate ... How can we set the horizontal alignment of JTable? - comp.lang ...... setWrapStyleWord(true); setPreferredSize(new ... JPanel in JTable cell - comp.lang.java.gui So you can just replace Jtable with QuickTable. Create afile - comp.lang.asm.x86... to work with DOS if you replace this line: mov ax,3d01h ; open existing file with that one: mov ax,3c01h ; create new file ... JPanel in JTable cell - comp.lang ... Replacing an existing jPanel with a new jPanel - comp.lang.java ...Hi everybody, I'm working on a project and basically I've developed a swing GUI using NetBeans Swing GUI builder. On one form, I have an existing JPanel that contains ... JAVA • View topic • Replacing an existing jPanel with a new jPanelReplacing an existing jPanel with a new jPanel. Programming and Web Development Forums - JAVA - GUI toolkits and windowing: AWT, IFC etc. Skip to content 7/24/2012 11:39:23 AM
|