• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Problem in JDialogBox

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
send ur code !

Kriti
 
Neha D
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic