File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Problem in JDialogBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem in JDialogBox" Watch "Problem in JDialogBox" New topic
Author

Problem in JDialogBox

Neha D
Ranch Hand

Joined: Oct 12, 2004
Posts: 32
Hi,

I have a JDialogBox which is displayed for two different actions.
When i double click on a table cell this dialog box is diplayed & also when i right click on the tabl cell this dialog gets displayed.

When it gets displayed for a double click all the components of that dialog are to be made visible. But when it gets displayed for a right click, one of the component (a panel on that dialog) should not be displayed & the space occupied by that component should be used evenly by other components.

Can anybody plz help me out with this problem.

Help is heartedly appreciated.

Thanx.
Regards,
NDT
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

NDT,

Welcome to Javaranch!

We don't have too many rules around here but we do have a Naming Policy that we require all members to adhere to. Please read this policy and then adjust your display name accordingly.

Thanks.


GenRocket - Experts at Building Test Data
Kriti Garg
Ranch Hand

Joined: Sep 13, 2004
Posts: 50
Hi Neha,

I think choosing the right layout acc to ur requirement will help u out

as u didnot mention all the components to be shown i cannot say which one will suite to your requirement.

as far as one panel is consiserderd,just track the event in ur Jialog
from which Jdiglog is shown (double or right click),u can set a flag also


and accordingly use add(component) and remove(component) method. for this panel.
Neha D
Ranch Hand

Joined: Oct 12, 2004
Posts: 32
Hey thanx Kriti

I have modified the layout.
Now I am using panels on JSplitPane & setting the divider location field of the JSplitPane when the dialog box is made visible on a right click so that the panel at the bottom of the JSplitPane is not visible.

But now the problem is that:
Along with the JSplitPane, I have 2 more panels on the JDialogContentPane & therefore I am using the GridBagLayout. The JSplitPane is in between of the 2 panels. Now when I change the divider location of the JSplitPane, the components on the panel which is at the top of the JSplitPane resize themselves as the layout is GridBagLayout. But their is a lot of gap between the components & it is looking wierd.

I want to adjust all these compoenents accordingly so that the applet looks proper.

Can you plz help me out in this.

Thanx.

Regards,
- Neha....
Kriti Garg
Ranch Hand

Joined: Sep 13, 2004
Posts: 50
send ur code !

Kriti
Neha D
Ranch Hand

Joined: Oct 12, 2004
Posts: 32
Heyy Kriti I am so sorry
I cannot send u the code as it is very confidential.....

Wait I'll explain it to you in a better way:

The are 3 components on the JDialog:
1) A JPanel
2) A JSplitPane - It has 2 JPanels
3) A JPanel

Now when I double click I can see the whole JDialog with all its components alligned properly... That is what i want.

Then when i right click I want the same dialog but one of the panel on the JSplitPane should not be visible.
And all the other Components should get alligned properly. Now the remaining panel on the JSplitPane should accuire the whole space. That the Panel does but their is a lot of gap between these components. And this is what i want to reduce.

Thanx.
Regards,
- Neha
Kriti Garg
Ranch Hand

Joined: Sep 13, 2004
Posts: 50
Hi,

what my expericence says u must be using GBC layout somewhere in ur this module.

GBC is powerful layout ,but if u donot use it correctly it can create blunder for u.

i am sending u a main class from which another class opens contiainig requied panels i have used BorderLayout for this.

go through this,hope it will help u out.



...........Main class............
package abc;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;

public class MainClass
extends JFrame {
private JButton btn1 = new JButton("Option 1");
private JButton btn2 = new JButton("Option 2");
private RanchWork ranchWork = new RanchWork();

public MainClass() {
getContentPane().setLayout(new FlowLayout());
getContentPane().add(btn1);
getContentPane().add(btn2);
setSize(200, 70);
setVisible(true);

btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ranchWork.addMyPanel();
ranchWork.pack();
ranchWork.setSize(500, 500);
ranchWork.setVisible(true);

}
});

btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ranchWork.removeMyPanel();
ranchWork.pack();
ranchWork.setSize(500, 500);
ranchWork.setVisible(true);
}
});

}

public static void main(String[] args) {
MainClass mainClass1 = new MainClass();
}

}


...........Dialog class..........


package abc;

import java.util.*;
import javax.swing.*;
import java.awt.*;

public class RanchWork
extends JDialog {
private JPanel panel3 = null;
private JSplitPane splitPane = null;

public RanchWork() {
init();
}

private void init() {
getContentPane().setLayout(new BorderLayout());

JPanel panel1 = new JPanel();
panel1.add(new JLabel("Panel 1"));

JPanel panel2 = new JPanel();
panel2.add(new JLabel("Panel 2"));

panel3 = new JPanel();
panel3.add(new JLabel("Panel 3"));

JPanel panel4 = new JPanel();
panel4.add(new JLabel("Panel 4"));

splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
panel2, panel3);

getContentPane().add(panel1, BorderLayout.NORTH);
getContentPane().add(splitPane, BorderLayout.CENTER);
getContentPane().add(panel4, BorderLayout.SOUTH);
}

protected void addMyPanel() {
if (splitPane.getRightComponent() == null) {
this.splitPane.add(panel3);
}
//
}

protected void removeMyPanel() {
if (splitPane.getRightComponent() != null) {
splitPane.remove(panel3);
}
}

}
Neha D
Ranch Hand

Joined: Oct 12, 2004
Posts: 32
hi Kriti,
Thanx a lot for the code. I had used the GBC layout for the dialog box & that was giving me some problems.

Well I used ur code, that is working perfectly fine & thanx for that again.

Regards,
- Neha
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Neha

You still have not conformed to our Naming Policy. Specifically you need your display name to be a First Last name format. Please do so or you risk having your account closed. We would rather keep you around here.

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in JDialogBox