javacmpalmer
asked on
JPanel/resizing/ problems
Hello!
I have 3 JPanels. Each JPanel has components on it. The bottom panel and its components should be only as big as its needs to be. The middle panel should be only as big as it needs to be and the top panel and its components should expand to take the rest of the space. I am having problems getting this to work. Here is the code I am starting with. I thought I could fix it with a grid bag layout but had problems. I would really appreciate some help.
Chris
private void init() {
setSize(600,600);
// Load an icon for applicaiton.
URL u = this.getClass().getClassLo ader().get Resource(C onstants.A PP_ICON);
setIconImage(Toolkit.getDe faultToolk it().getIm age(u));
_mview = new MViewPane();
_mview.setParams(Constants .MARVIN_DE FAULT);
_mview.setEditable(2);
_mview.setDetachable(true) ;
_mview.setSize(450,400);
_mview.setMinimumSize(new Dimension(450,400));
JPanel jpMol = new JPanel(new BorderLayout());
JPanel jpAction = new JPanel(new GridLayout(4,2,5,5));
jpMol.setBorder(BorderFact ory.create TitledBord er("Curren t Molecule:"));
jpAction.setBorder(BorderF actory.cre ateTitledB order("Act ions:"));
jpMol.add(_mview,BorderLay out.CENTER );
// Notes/Instructions//////// ////////// ////////// ////////// ////////// //
JPanel jpNotes = new JPanel();
jpNotes.setBorder(BorderFa ctory.crea teTitledBo rder("Inst ructions:" ));
JTextArea marvinNote = new JTextArea();
marvinNote.setEditable(fal se);
// Setup the notes ////////////////////////// ////////// ////////// ///
StringBuffer note = new StringBuffer("1. Double click on the molecule to open Marvin Draw.");
note.append("\n2. Edit the molecule.");
marvinNote.setText(note.to String());
jpNotes.add(marvinNote);
marvinNote.setBackground(j pNotes.get Background ());
////////////////////////// ////////// ////////// ////////// ////////// //
JLabel editor = new JLabel("External Sketcher:",JLabel.RIGHT);
JLabel edit = new JLabel("Edit:",JLabel.RIGH T);
JLabel save = new JLabel("Save:",JLabel.RIGH T);
JLabel close = new JLabel("Close:",JLabel.RIG HT);
// Create the combo box, select item at index 4.
// Indices start at 0, so 4 specifies the pig.
sketchList = new JComboBox(Constants.SKETCH ERS);
// Only one right now change it later....
sketchList.setSelectedInde x(0);
// sketchList.setSelectedInde x(getDefau ltSketcher ());
CloseMolWorkBenchAction c = new CloseMolWorkBenchAction();
registerAction(c);
EditMolAction ema = new EditMolAction();
registerAction(ema);
jbEdit = new JButton(ema);
SaveMolAction sma = new SaveMolAction();
registerAction(sma);
jbSave = new JButton(sma);
jbSave.setEnabled(false);
jbClose = new JButton(c);
jpAction.add(editor);
jpAction.add(sketchList);
jpAction.add(edit);
jpAction.add(jbEdit);
jpAction.add(save);
jpAction.add(jbSave);
jpAction.add(close);
jpAction.add(jbClose);
// GridBagLayout gridbag = new GridBagLayout();
// GridBagConstraints con = new GridBagConstraints();
// this.getContentPane().setL ayout(grid bag);
// con.fill = GridBagConstraints.BOTH;
// con.weightx = 1.0;
// con.weighty = 1.0;
// con.gridwidth = GridBagConstraints.REMAIND ER;
// con.gridheight = 1;
// con.ipady = 300;
// gridbag.setConstraints(jpM ol,con);
// this.getContentPane().add( jpMol);
// con.ipady = 0;
// con.weighty = 1.0;
// con.fill = GridBagConstraints.HORIZON TAL;
// gridbag.setConstraints(jpN otes,con);
// this.getContentPane().add( jpNotes);
// con.fill = GridBagConstraints.HORIZON TAL;
// con.weighty = 1.0;
// con.anchor = GridBagConstraints.SOUTH;
// gridbag.setConstraints(jpA ction,con) ;
// this.getContentPane().add( jpAction);
getContentPane().add(jpMol ,BorderLay out.NORTH) ;
getContentPane().add(jpNot es,BorderL ayout.CENT ER);
getContentPane().add(jpAct ion,Border Layout.SOU TH);
}
I have 3 JPanels. Each JPanel has components on it. The bottom panel and its components should be only as big as its needs to be. The middle panel should be only as big as it needs to be and the top panel and its components should expand to take the rest of the space. I am having problems getting this to work. Here is the code I am starting with. I thought I could fix it with a grid bag layout but had problems. I would really appreciate some help.
Chris
private void init() {
setSize(600,600);
// Load an icon for applicaiton.
URL u = this.getClass().getClassLo
setIconImage(Toolkit.getDe
_mview = new MViewPane();
_mview.setParams(Constants
_mview.setEditable(2);
_mview.setDetachable(true)
_mview.setSize(450,400);
_mview.setMinimumSize(new Dimension(450,400));
JPanel jpMol = new JPanel(new BorderLayout());
JPanel jpAction = new JPanel(new GridLayout(4,2,5,5));
jpMol.setBorder(BorderFact
jpAction.setBorder(BorderF
jpMol.add(_mview,BorderLay
// Notes/Instructions////////
JPanel jpNotes = new JPanel();
jpNotes.setBorder(BorderFa
JTextArea marvinNote = new JTextArea();
marvinNote.setEditable(fal
// Setup the notes //////////////////////////
StringBuffer note = new StringBuffer("1. Double click on the molecule to open Marvin Draw.");
note.append("\n2. Edit the molecule.");
marvinNote.setText(note.to
jpNotes.add(marvinNote);
marvinNote.setBackground(j
//////////////////////////
JLabel editor = new JLabel("External Sketcher:",JLabel.RIGHT);
JLabel edit = new JLabel("Edit:",JLabel.RIGH
JLabel save = new JLabel("Save:",JLabel.RIGH
JLabel close = new JLabel("Close:",JLabel.RIG
// Create the combo box, select item at index 4.
// Indices start at 0, so 4 specifies the pig.
sketchList = new JComboBox(Constants.SKETCH
// Only one right now change it later....
sketchList.setSelectedInde
// sketchList.setSelectedInde
CloseMolWorkBenchAction c = new CloseMolWorkBenchAction();
registerAction(c);
EditMolAction ema = new EditMolAction();
registerAction(ema);
jbEdit = new JButton(ema);
SaveMolAction sma = new SaveMolAction();
registerAction(sma);
jbSave = new JButton(sma);
jbSave.setEnabled(false);
jbClose = new JButton(c);
jpAction.add(editor);
jpAction.add(sketchList);
jpAction.add(edit);
jpAction.add(jbEdit);
jpAction.add(save);
jpAction.add(jbSave);
jpAction.add(close);
jpAction.add(jbClose);
// GridBagLayout gridbag = new GridBagLayout();
// GridBagConstraints con = new GridBagConstraints();
// this.getContentPane().setL
// con.fill = GridBagConstraints.BOTH;
// con.weightx = 1.0;
// con.weighty = 1.0;
// con.gridwidth = GridBagConstraints.REMAIND
// con.gridheight = 1;
// con.ipady = 300;
// gridbag.setConstraints(jpM
// this.getContentPane().add(
// con.ipady = 0;
// con.weighty = 1.0;
// con.fill = GridBagConstraints.HORIZON
// gridbag.setConstraints(jpN
// this.getContentPane().add(
// con.fill = GridBagConstraints.HORIZON
// con.weighty = 1.0;
// con.anchor = GridBagConstraints.SOUTH;
// gridbag.setConstraints(jpA
// this.getContentPane().add(
getContentPane().add(jpMol
getContentPane().add(jpNot
getContentPane().add(jpAct
}
ASKER
I don't think I completely understand. I have three panels. The above is a solution when you have two. I need to wedge one in the middle but not do what normal something set with .CENTER does.
Chris
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are correct.....just got off a plane....zzzzzzz Thank you.
Chris
Chris
Chris,
Happy to help :)
Happy to help :)
newpanel.add(BorderLayout.
newpanel.add(BorderLayout.
add(BorderLayout.CENTER, newpanel);
add(BorderLayout.SOUTH, bottom);