Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-17-2008, 02:17 AM
Member
 
Join Date: Apr 2008
Posts: 1
LearningJavaASAP is on a distinguished road
How do I modify a specific component within a active internalframe?
Hello everybody,

I am still learning java at this point, but I seem to have surpassed the 3 java books I own.

I have an issue here that I am confident that most of you can answer.

I am attempting to change the icon of a button in a internalframe when pressed. The code below shows the text of a button changing (but only the last iframe is being changed, not the active iframe). By answering this question I will understand how to interact with internal frames.
Here is a stripped down version of the code:

Code:
import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.OverlayLayout; import javax.swing.ScrollPaneConstants; import javax.swing.UIManager; import javax.swing.event.InternalFrameEvent; import javax.swing.event.InternalFrameListener; public class TestFrameButton extends JDesktopPane{ private static final long serialVersionUID = 1L; JDesktopPane desk; JDesktopPane ifdesk; JScrollPane scrollpane; JInternalFrame iframe; JFrame frame; JList jList1; JInternalFrame currentframe; Integer currentframenumber; String currentframename; Boolean[] downuptracker; Integer deskwidth = 1000; Integer deskheight = 1000; Integer scrollwidth = 1000; Integer scrollheight = 1000; JButton DownUpButton; public static void main(String[] args) { TestFrameButton d = new TestFrameButton(); } public TestFrameButton(){ downuptracker = new Boolean [99]; frame = new JFrame("Test Frame Button"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); scrollpane = new JScrollPane(desk, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); scrollpane.setPreferredSize(new java.awt.Dimension(scrollwidth, scrollheight)); desk = new JDesktopPane(); desk.setPreferredSize(new java.awt.Dimension(deskwidth, deskheight)); int i = 5; for (int j = 0; j <= i; j++){ UIManager.getDefaults().put("InternalFrame.icon", ""); iframe = new JInternalFrame("Internal Frame: " + j, false, true, false, false); iframe.setName(String.valueOf(j)); iframe.setBounds(30*j, 30*j,265 , 80); iframe.addInternalFrameListener(new InternalFrameListener(){ public void internalFrameClosing(InternalFrameEvent e) { } public void internalFrameClosed(InternalFrameEvent e) { } public void internalFrameOpened(InternalFrameEvent e) { } public void internalFrameIconified(InternalFrameEvent e) { } public void internalFrameDeiconified(InternalFrameEvent e) { } public void internalFrameActivated(InternalFrameEvent e) { currentframe = e.getInternalFrame(); currentframename = e.getInternalFrame().getName(); currentframenumber = Integer.valueOf(currentframename); } public void internalFrameDeactivated(InternalFrameEvent e) { } }); iframe.setTitle("Internal Frame :" + j); iframe.setVisible(true); downuptracker[j] = true; ifdesk = new JDesktopPane(); iframe.getContentPane().add(ifdesk, BorderLayout.CENTER); DownUpButton = new JButton("Old Icon here"); ifdesk.add(DownUpButton); DownUpButton.setBounds(0, 0, 130, 20); DownUpButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (downuptracker[currentframenumber].equals(true)){ // Colapse frame here and change icon DownUpButton.setText("New Icon here"); downuptracker[currentframenumber] = false; }else{ // Expand frame here and change icon DownUpButton.setText("Old Icon here"); downuptracker[currentframenumber] = true; } } }); desk.add(iframe); iframe.moveToFront(); } scrollpane.setViewportView(desk); frame.add(scrollpane); scrollpane.setVisible(true); frame.setSize(800,600); frame.setVisible(true); } }
Thank you in advance.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-24-2008, 07:35 PM
Senior Member
 
Join Date: Jul 2007
Posts: 910
hardwired is on a distinguished road
Code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class TFB { private static final long serialVersionUID = 1L; JDesktopPane desk; JDesktopPane ifdesk; JScrollPane scrollpane; JInternalFrame iframe; JFrame frame; JList jList1; JInternalFrame currentframe; Integer currentframenumber; String currentframename; Boolean[] downuptracker; Integer deskwidth = 1000; Integer deskheight = 1000; Integer scrollwidth = 1000; Integer scrollheight = 1000; JButton DownUpButton; public static void main(String[] args) { new TFB(); } public TFB(){ downuptracker = new Boolean [99]; frame = new JFrame("Test Frame Button"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); scrollpane = new JScrollPane(desk, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); scrollpane.setPreferredSize(new Dimension(scrollwidth, scrollheight)); // If you're going to make a new JDesktopPane here there is // no need to have the enclosing class extend JDesktopPane. desk = new JDesktopPane(); desk.setPreferredSize(new Dimension(deskwidth, deskheight)); // Only need to do this one time. UIManager.getDefaults().put("InternalFrame.icon", ""); int i = 5; for (int j = 0; j <= i; j++){ // UIManager.getDefaults().put("InternalFrame.icon", ""); iframe = new JInternalFrame("Internal Frame: " + j, false, true, false, false); iframe.setName(String.valueOf(j)); iframe.setBounds(30*j, 30*j,265 , 80); iframe.addInternalFrameListener(new InternalFrameListener(){ public void internalFrameClosing(InternalFrameEvent e) {} public void internalFrameClosed(InternalFrameEvent e) {} public void internalFrameOpened(InternalFrameEvent e) {} public void internalFrameIconified(InternalFrameEvent e) {} public void internalFrameDeiconified(InternalFrameEvent e) {} public void internalFrameActivated(InternalFrameEvent e) { currentframe = e.getInternalFrame(); currentframename = e.getInternalFrame().getName(); currentframenumber = Integer.valueOf(currentframename); System.out.println("activatedFrame name = " + currentframename); } public void internalFrameDeactivated(InternalFrameEvent e) {} }); iframe.setTitle("Internal Frame :" + j); iframe.setVisible(true); downuptracker[j] = true; // ifdesk = new JDesktopPane(); // iframe.getContentPane().add(ifdesk, BorderLayout.CENTER); DownUpButton = new JButton("Old Icon here"); // ifdesk.add(DownUpButton); iframe.setLayout(null); DownUpButton.setBounds(0, 0, 130, 20); iframe.getContentPane().add(DownUpButton); DownUpButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // Try getting a reference to the button that // sent this event: JButton button = (JButton)e.getSource(); if (downuptracker[currentframenumber].equals(true)) { // Colapse frame here and change icon // Since DownUpButton has been declared as a // member variable in class scope this reference // to "DownUpButton" will always refer/point to // the last instance created. //DownUpButton.setText("New Icon here"); button.setText("New Icon here"); downuptracker[currentframenumber] = false; }else{ // Expand frame here and change icon //DownUpButton.setText("Old Icon here"); button.setText("Old Icon here"); downuptracker[currentframenumber] = true; } } }); desk.add(iframe); iframe.moveToFront(); } scrollpane.setViewportView(desk); frame.add(scrollpane); // scrollpane.setVisible(true); frame.setSize(800,600); frame.setVisible(true); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Modify A* Algorithm prakharbirla Advanced Java 1 02-13-2008 07:25 PM
Modify/create AVI's INFO BLOCK Agus211 New To Java 0 02-11-2008 04:20 PM
Active Content enable problem kasipandian JavaServer Pages (JSP) and JSTL 0 02-01-2008 03:15 PM
Accessing Active Directory javaplus Advanced Java 1 01-05-2008 12:25 AM
Rejecting connections from a specific IP javaplus Networking 2 12-21-2007 03:28 PM


All times are GMT +3. The time now is 12:39 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org