Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #5317
| X-Received | by 10.224.58.77 with SMTP id f13mr468428qah.7.1364968509787; Tue, 02 Apr 2013 22:55:09 -0700 (PDT) |
|---|---|
| X-Received | by 10.50.217.225 with SMTP id pb1mr2210513igc.5.1364968509744; Tue, 02 Apr 2013 22:55:09 -0700 (PDT) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!t2no35647250qal.0!news-out.google.com!v17ni20587qad.0!nntp.google.com!ca1no26076308qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.java.gui |
| Date | Tue, 2 Apr 2013 22:55:09 -0700 (PDT) |
| In-Reply-To | <41A5232C.70F7@nospam_cox.net> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=64.104.252.247; posting-account=62_JqAoAAACOxTtW1F8l1py-qk6fw_Sv |
| NNTP-Posting-Host | 64.104.252.247 |
| References | <41A5232C.70F7@nospam_cox.net> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <677c5cd9-ccee-413e-9e3f-9827c37e76f5@googlegroups.com> (permalink) |
| Subject | Re: JSplitPane resize woes |
| From | vicky.lalit@gmail.com |
| Cc | lmcoon@nospam_cox.net |
| Injection-Date | Wed, 03 Apr 2013 05:55:09 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.java.gui:5317 |
Show key headers only | View raw
Hi Experts,
I have an issue with my JSpiltPane. Below is the code snippet.
Problem is I have one panel added in Right side of the Spilt Pane, and that Panel has many components like Label,TextArea,Panel,Checkbox etc. And this panel is itself a Titled Border Panel.
When I am maximizing my screen, the Right side panel is not resizing. I tried a lot with the layouts but no Luck.
Would be great if someone can help me on this.
------------------------
import javax.swing.JFrame;
/*
* GridBagLayoutDemo.java requires no other files.
*/
import java.awt.*;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
class SplitPane
extends JFrame
{
private JSplitPane splitPaneV;
private JSplitPane splitPaneH;
private JPanel panel1;
private JPanel panel2;
private JPanel panel3;
public SplitPane()
{
setTitle( "Split Pane Application" );
//setBackground( Color.gray );
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
// Create the panels
createPanel1();
createPanel2();
//createPanel3();
// Create a splitter pane
// splitPaneV = new JSplitPane( JSplitPane.VERTICAL_SPLIT );
//topPanel.add( splitPaneV, BorderLayout.CENTER );
JPanel main = new JPanel();
main.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 0.5;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(5, 5, 0, 0);
JPanel acGlobalPlanel = panel2;
main.add(acGlobalPlanel,gbc);
JPanel currentPanel = new JPanel();
currentPanel.setLayout(new BorderLayout());
/*currentPanel.setLayout(new GridBagLayout());
GridBagConstraints g = new GridBagConstraints();
g.anchor = GridBagConstraints.CENTER;
g.fill = GridBagConstraints.BOTH;
g.weightx = 100;
g.weighty = 100;
g.gridx = 0;
g.gridy = 0;*/
splitPaneH = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT,panel1,currentPanel );
splitPaneH.setContinuousLayout(true);
splitPaneH.setPreferredSize( new Dimension(600,600));
topPanel.add( splitPaneH, BorderLayout.CENTER );
JPanel curr = (JPanel)splitPaneH.getRightComponent();
curr.add(main, BorderLayout.CENTER);
//currentPanel.add(main, BorderLayout.CENTER);
/*currentPanel.validate();
currentPanel.repaint();*/
Border matteBorder = BorderFactory.createMatteBorder(1, 0, 0, 0,
SystemColor.controlDkShadow);
Border titledBorder = BorderFactory.createTitledBorder(matteBorder,
"Circuit Attributes",
TitledBorder.LEFT,
TitledBorder.ABOVE_TOP);
currentPanel.setBorder(titledBorder);
currentPanel.revalidate();
currentPanel.repaint();
//splitPaneV.setLeftComponent( splitPaneH );
//splitPaneV.setResizeWeight(0.333);
//splitPaneV.setContinuousLayout(true);
//splitPaneV.setOneTouchExpandable(true);
//splitPaneV.setRightComponent( panel3 );
pack();
setLocationRelativeTo(getOwner());
}
public void createPanel1()
{
panel1 = new JPanel();
panel1.setLayout( new GridBagLayout() );
GridBagConstraints gc = new GridBagConstraints();
gc.anchor = GridBagConstraints.CENTER;
gc.fill = GridBagConstraints.VERTICAL;
gc.gridx = 0;
gc.gridy = 0;
gc.insets = new Insets(10, 7, 0, 7);
// Add some buttons
panel1.add( new JButton( "First" ), gc );
gc.gridx = 0;
gc.gridy = 1;
panel1.add( new JButton( "Second" ), gc );
gc.gridx = 0;
gc.gridy = 2;
panel1.add( new JButton( "Third" ), gc );
gc.gridx = 0;
gc.gridy = 3;
panel1.add( new JButton( "Fourth" ), gc );
gc.gridx = 0;
gc.gridy = 4;
panel1.add( new JButton( "Fifth" ), gc );
}
public void createPanel2()
{
panel2 = new JPanel();
panel2.setBorder(new TitledBorder("Global Attributes"));
panel2.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(10, 7, 0, 7);
VpslNameAttr vpslNameAttr = new VpslNameAttr();
panel2.add(vpslNameAttr.getUI(),gbc);
gbc.gridx = 0;
gbc.gridy = 1;
VPNIdAttr vplsDescAttr = new VPNIdAttr();
panel2.add(vplsDescAttr.getUI(),gbc);
}
public void createPanel3()
{
panel3 = new JPanel();
panel3.setLayout( new BorderLayout() );
panel3.setPreferredSize( new Dimension( 600, 400 ) );
panel3.setMinimumSize( new Dimension( 600, 400 ) );
panel3.add( new JLabel( "Notes:" ), BorderLayout.NORTH );
panel3.add( new JTextArea(), BorderLayout.CENTER );
}
public static void main( String args[] )
{
// Create an instance of the test application
SplitPane mainFrame = new SplitPane();
mainFrame.setSize(600, 400);
mainFrame.setVisible( true );
}
}
class VpslNameAttr {
JTextField pwNameTF;
private JPanel p;
VpslNameAttr() {
p = new JPanel();
//p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
p.setLayout( new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 10000;
gbc.gridheight = 10000;
p.add(new JLabel("Name: "),gbc);
//p.add(new JLabel("Name: "));
pwNameTF = new JTextField();
pwNameTF.setPreferredSize(new Dimension(130, 20));
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 1;
gbc.gridy = 0;
gbc.gridwidth = 10000;
gbc.gridheight = 10000;
p.add(pwNameTF,gbc);
//p.add(pwNameTF);
}
public JPanel getUI() {
return p;
}
public String getPWName() {
return pwNameTF.getText();
}
}
class VPNIdAttr {
TextField vpnIdAttrTF;
private JPanel p;
VPNIdAttr()
{
p = new JPanel();
//p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.NONE;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 100;
gbc.gridheight = 100;
p.add(new JLabel("VPN ID: "),gbc);
//p.add(new JLabel("VPN ID: "));
vpnIdAttrTF = new TextField(15);
vpnIdAttrTF.setPreferredSize(new Dimension(130, 20));
gbc.anchor = GridBagConstraints.CENTER;
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 1;
gbc.gridy = 0;
gbc.gridwidth = 100;
gbc.gridheight = 100;
p.add(vpnIdAttrTF,gbc);
//p.add(vpnIdAttrTF);
}
public JPanel getUI() {
return p;
}
public String getVPNId() {
return vpnIdAttrTF.getText();
}
}
--------------------------------------------------
On Thursday, November 25, 2004 5:41:24 AM UTC+5:30, Larry Coon wrote:
> I've reduced my problem to a short, self-contained example,
> below. I have a JFrame that has a JSplitPane, that has a
> JTree (left) and JTextArea (right). I can't get resize
> behavior to work correctly. I've tried many combinations of
> setting minimum size & preferred size on each/all of the
> components, but nothing did what I wanted. Here's a minimal
> example:
>
> import java.awt.*;
> import javax.swing.*;
>
> public class SplitPaneDemo extends JFrame {
> public SplitPaneDemo() {
> super("Split Pane Demo");
>
> Container container = getContentPane();
> JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
> splitPane.setLeftComponent(new JTree());
>
> JTextArea textArea = new JTextArea();
> splitPane.setRightComponent(textArea);
> textArea.setLineWrap(true);
>
> container.add(splitPane, BorderLayout.CENTER);
>
> setDefaultCloseOperation(EXIT_ON_CLOSE);
> setSize(500, 500);
> setVisible(true);
> }
>
> public static void main(String[] args) {
> new SplitPaneDemo();
> }
> }
>
> If I dont setLineWrap(true) then I can move the JSplitPane's
> separator bar correctly. As it is here, I can move it left,
> but not right. It seems like the JTextArea is resizable
> bigger, but not smaller, when LineWrap is true.
>
> My actual program is a lot more involved (the right hand side
> is a JTextArea in a JPanel (along with other components) on
> a JTabbedField on the right hand side of the JSplitPane), but
> I'm obviously missing something basic. What's the CORRECT
> way to get the above working correctly?
>
> Thanks.
Back to comp.lang.java.gui | Previous | Next — Next in thread | Find similar
Re: JSplitPane resize woes vicky.lalit@gmail.com - 2013-04-02 22:55 -0700 Re: JSplitPane resize woes "John B. Matthews" <nospam@nospam.invalid> - 2013-04-03 17:57 -0400
csiph-web