Question

How to add components to JPanel

Asked by: Stian_B

Hi,

I just cant get this to work. I'm trying to add components to a JPanel called "hoyre_jpanel" as showed in the code. I've tryed using borderlayout, without borderlayout, validate, repaint and everything else i've found online. Any help would be great.

btw, there are no errors in under compilation, and the hoyre_jpanel.getComponentCount() shows there are added components to the jpanel, but they are not showing.

Stian

JButton b = new JButton("asdf");
hoyre_jpanel.add(b, BorderLayout.NORTH);
hoyre_jpanel.validate();
hoyre_jpanel.repaint();

                                  
1:
2:
3:
4:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-06-16 at 07:50:07ID24495747
Tags

java

,

swing

,

awt

Topics

Java AWT & Swing

,

New to Java Programming

Participating Experts
1
Points
500
Comments
7

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. JScrollPane + JPanel
    My problem is that I have this class that extends JApplet and has 3 JPanel and an instance from another class that extends JPanel (I will call it class2) inside it. My problem is that I'm inserting class2 inside a JScrollPane than I insert JScrollPane inside my JApplet, but ...
  2. JPanel & JFrame
    Hello, I made an Application that uses a JFrame that contains several JPanels. In addtion my application requires a wizard-like operaton, I did that by removing and adding JPanels and components as needed. But it turns out malfunction after some add's and remove's, do you ...
  3. JTabbedPane and Jpanel
    hi! Can anybody take a look this? (It is hard to explain w/o actual applet.) http://webdev.apl.jhu.edu/~rbe/java/Homework4/index.html If you drag up the bottom of window, the button disapears. My question is: Is there two panels in this applet? if so, JTabbedPane is top of ...
  4. Problem validating JPanel, component removed ghosting
    I have a jpanel on a tab of a JtabbedPane, which through a jbutton allows you to add jlabels dynamically. To remove the jlabels, i put all of the jlabels clicked on by the mouse into a vector and then when the delete labels jbutton is pressed, delete all of the jlabels in th...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: 0791882310Posted on 2009-06-16 at 07:53:42ID: 24638642

you dont have to validate or repaint, the code you have to add the button to the panel will work fine, there has to be a problem with the rest of your code somewhere... maybe adding the panel to the frame??.. or displaying the frame??.. can you post the rest of your layout code so we can have a look at it?

 

by: Stian_BPosted on 2009-06-16 at 07:57:47ID: 24638684

here is the code creating the layout, i'm using netbeans "drag and drop" to create the components that will not change, that is the "venstre_jpanel" and "hoyre_jpanel".

 * KasseView.java
 */
 
package kasse;
 
import java.awt.BorderLayout;
import java.awt.GridLayout;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
 
/**
 * The application's main frame.
 */
public class KasseView extends FrameView {
 
    public KasseView(SingleFrameApplication app) {
        super(app);
 
        initComponents();
        
 
        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);
 
        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }
 
    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = KasseApp.getApplication().getMainFrame();
            aboutBox = new KasseAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        KasseApp.getApplication().show(aboutBox);
    }
 
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
 
        mainPanel = new javax.swing.JPanel();
        venstre_jpanel = new javax.swing.JPanel();
        nyVareButton = new javax.swing.JButton();
        hoyre_jpanel = new javax.swing.JPanel();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
 
        mainPanel.setMaximumSize(new java.awt.Dimension(1024, 768));
        mainPanel.setMinimumSize(new java.awt.Dimension(1024, 768));
        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setPreferredSize(new java.awt.Dimension(1024, 768));
        mainPanel.setRequestFocusEnabled(false);
        mainPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mainPanelMouseClicked(evt);
            }
        });
 
        venstre_jpanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        venstre_jpanel.setMaximumSize(new java.awt.Dimension(500, 748));
        venstre_jpanel.setMinimumSize(new java.awt.Dimension(500, 748));
        venstre_jpanel.setName("venstre_jpanel"); // NOI18N
        venstre_jpanel.setPreferredSize(new java.awt.Dimension(500, 748));
 
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(kasse.KasseApp.class).getContext().getResourceMap(KasseView.class);
        nyVareButton.setText(resourceMap.getString("nyVareButton.text")); // NOI18N
        nyVareButton.setName("nyVareButton"); // NOI18N
        nyVareButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                nyVareButtonMouseClicked(evt);
            }
        });
 
        javax.swing.GroupLayout venstre_jpanelLayout = new javax.swing.GroupLayout(venstre_jpanel);
        venstre_jpanel.setLayout(venstre_jpanelLayout);
        venstre_jpanelLayout.setHorizontalGroup(
            venstre_jpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(venstre_jpanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(nyVareButton)
                .addContainerGap(417, Short.MAX_VALUE))
        );
        venstre_jpanelLayout.setVerticalGroup(
            venstre_jpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, venstre_jpanelLayout.createSequentialGroup()
                .addContainerGap(715, Short.MAX_VALUE)
                .addComponent(nyVareButton)
                .addContainerGap())
        );
 
        hoyre_jpanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        hoyre_jpanel.setMaximumSize(new java.awt.Dimension(500, 748));
        hoyre_jpanel.setMinimumSize(new java.awt.Dimension(500, 748));
        hoyre_jpanel.setName("hoyre_jpanel"); // NOI18N
        hoyre_jpanel.setPreferredSize(new java.awt.Dimension(500, 748));
 
        javax.swing.GroupLayout hoyre_jpanelLayout = new javax.swing.GroupLayout(hoyre_jpanel);
        hoyre_jpanel.setLayout(hoyre_jpanelLayout);
        hoyre_jpanelLayout.setHorizontalGroup(
            hoyre_jpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 498, Short.MAX_VALUE)
        );
        hoyre_jpanelLayout.setVerticalGroup(
            hoyre_jpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 749, Short.MAX_VALUE)
        );
 
        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(venstre_jpanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(hoyre_jpanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(hoyre_jpanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE)
                    .addComponent(venstre_jpanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 751, Short.MAX_VALUE))
                .addContainerGap())
        );
 
        mainPanel.getAccessibleContext().setAccessibleName(resourceMap.getString("mainPanel.AccessibleContext.accessibleName")); // NOI18N
 
        statusPanel.setName("statusPanel"); // NOI18N
 
        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
 
        statusMessageLabel.setName("statusMessageLabel"); // NOI18N
 
        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
 
        progressBar.setName("progressBar"); // NOI18N
 
        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 1026, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 856, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );
 
        jMenuBar1.setName("jMenuBar1"); // NOI18N
 
        jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
        jMenu1.setName("jMenu1"); // NOI18N
        jMenuBar1.add(jMenu1);
 
        jMenu2.setText(resourceMap.getString("jMenu2.text")); // NOI18N
        jMenu2.setName("jMenu2"); // NOI18N
        jMenuBar1.add(jMenu2);
 
        setComponent(mainPanel);
        setStatusBar(statusPanel);
    }// </editor-fold>
 
    private void mainPanelMouseClicked(java.awt.event.MouseEvent evt) {                                       
        // TODO add your handling code here:
    }                                      
 
    private void fyllVareVindu(String varegruppe){
        //finner antall varer for den aktuelle gruppe
 
        JPanel varevindu = new JPanel(new GridLayout(4,2));
    }
    private void nyVareButtonMouseClicked(java.awt.event.MouseEvent evt) {
        //lager vindu for ny vare på venstresiden av skjermen
        Venstreside JPanelvenstre = new Venstreside();
        JButton b = new JButton("asdf");
        hoyre_jpanel.add(b, BorderLayout.NORTH);
        hoyre_jpanel.validate();
        hoyre_jpanel.repaint();
        JPanelvenstre.nyVareVenstreside(venstre_jpanel);
 
}
 
    // Variables declaration - do not modify
    private javax.swing.JPanel hoyre_jpanel;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JButton nyVareButton;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JPanel venstre_jpanel;
    // End of variables declaration
 
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    public javax.swing.JPanel venstreSide;
    public double frame_bredde;
    public double frame_hoyde;
 
    private JDialog aboutBox;
    private JDialog nyVare;
}
                                              
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:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:

Select allOpen in new window

 

by: 0791882310Posted on 2009-06-16 at 08:24:05ID: 24638934

is there a reason why you are wanting to add a button to the layout when a button is clicked??.. the way it is right now netbeans is using a group layout manager, so you can't just add a component to your panel.. and you can't change it's layout manager... real world scenario would be to use a toggle button, or to have the button placed using netbeans "drag and drop" and then set it's visibility to no until the action to show it.... so in your constructor method would be

whateverButton.setVisible(false);

then in your action would be

whateverButton.setVisible(true);

 

by: Stian_BPosted on 2009-06-16 at 08:30:06ID: 24639002

ok thanks for the reply.

The button was just a test to add a component, what i really want to do is replace all content in the JPanel venstre_jpanel with many labels and textfields (like a web form), to register a new product, user or whatever. but i think setVisible on all those components might not be a good solution, and Netbeans won't let me place components on top of each other, so i have to remove the content of the jpanel and add new ones..

I'm thinking maybe to drop the netbeans drag and drop, do you believe it would be easier to switch content then?

 

by: Stian_BPosted on 2009-06-16 at 08:47:57ID: 24639217

maybe you could just put me in the right direction? and i will gladly accept it as a solution! whether to use gridlayout on the whole thing or something else.

Here's what i plan to code: Main Jpanel covering the whole frame, with two large JPanels, right and left. All the content within this two jpanels will be replaced at some time by the user choosing to for example show the form for adding a new user or product in the database.

stian

 

by: Stian_BPosted on 2009-06-16 at 12:10:19ID: 31592995

not excactly solution, but you got me on the right track:)
tnx

 

by: 0791882310Posted on 2009-06-16 at 12:38:10ID: 24641681

ok what it sounds like your doing is lets say... some type of user registration where there will be more than one page of stuff to fill out right??... you notice when you install something... or have software when you have a next button to hit... that the page kinda flashes before the new content is loaded??.. that's because they are different frames... what you can do is not use netbeans wysiwyg and construct each page of the "form" in a frame, and then call the frame when need be... i can explain more if you need me to...

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...