• 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
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

JSplitterView treats panes differently

 
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using the JSplitter near (just scroll down a bit) http://java.sun.com/developer/onlineTraining/GUI/Swing1/shortcourse.html#JFCTabs as a guide.

My program works but the upper pane is allways scrunched (distorted). It does not fill the entire frame like the applet in the bottom pane does.

It does not seem to be a problem with the applets inside each pane because the upper one is always scrunched, regardless of whether it is MatrixView or GraphicsOnly. (Incidently, these are very similar applets that implement Craig's panning and zooming from the Java Other API's forum).

How can I make swing treat each pane the same?

Thanks,
Siegfried



import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.HeadlessException;

import javax.swing.JApplet;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
/**
*
*/

/**
* @author Siegfried Heintze
*
*/
public class SplitterView extends JApplet {

private Component m_viewTop;
private Component m_viewBottom;

/**
* @param top
* @param bottom
* @throws HeadlessException
*/
public SplitterView(Component top, Component bottom) throws HeadlessException {
super();
m_viewTop = top;
m_viewBottom = bottom;
}
/**
* @throws HeadlessException
*/
public SplitterView() throws HeadlessException {
super();
// TODO Auto-generated constructor stub
}
public void init(){
setLayout(new BorderLayout());
m_viewTop.setMinimumSize(new Dimension(0,100));
m_viewBottom.setMinimumSize(new Dimension(0,10));
JSplitPane pane = new JSplitPane( JSplitPane.VERTICAL_SPLIT, m_viewTop, m_viewBottom);
pane.setDividerLocation(.5);
pane.setOneTouchExpandable(true);
add(pane, BorderLayout.CENTER);
}

/**
* @param args
*/
public static void main(String[] args) {
/*
JTree tree = new JTree();
String[] items = {"a", "two", "three", "four", "five", "six", "seven"};
JList list = new JList(items);
JApplet applet = new SplitterView(new JScrollPane(tree), new JScrollPane(list));
*/
JApplet [] k = new JApplet[]{new GraphicsOnly(), new MatrixView()};
for(JApplet j : k) j.init();
JApplet applet = new SplitterView(k[0],k[1]);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(applet);
f.setSize(400,400);
f.setLocation(200,200);
// Since there is no AppletContext we have to
// call the required methods in the applet.
applet.init();
f.setVisible(true);
}
public void setViewBottom(JScrollPane bottom) {
m_viewBottom = bottom;
}
public void setViewTop(JScrollPane top) {
m_viewTop = top;
}

}
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if the problem is the divider location, it needs to be set after setVisible(true).
(alternatively, you can use setResizeWeight(.5))

 
Siegfried Heintze
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
That solution works great until I put it that splitterView inside a JTabbedPane with the add function.

As you can see, I'm not clear about weather I need JPanels or not for each tabbed pane.

Now the old symptoms are back where the top pain is distorted. And I cannot figure out where to put the "applet.pane.setDividerLocation(.5);//<-----must be after setVisible(true);" to accommodate an applet where there is no main.

I'm trying to follow the example at http://www.isr.umd.edu/~austin/ence200.d/swing.d/components.d/DemoTabbedPane.java

Why would JTabbedPane.add make the upper splitter pane act differently?

Thanks,
Siegfried



// modified from http://www.isr.umd.edu/~austin/ence200.d/swing.d/components.d/DemoTabbedPane.java

/*
*/

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

public class DemoTabbedPane extends JApplet {

Container container = null;

private JTabbedPane tabbedPane;
private JPanel[] panel = new JPanel[]{createPage1(), createPage2(), createPage3()};
JApplet [] k = new JApplet[]{new GraphicsOnly(), new MatrixView()};
JPanel [] p = new JPanel[]{new JPanel(), new JPanel()};
{
for(int j= k.length-1; j >= 0; --j ){
k[j].init();
p[j].add(k[j]);

}
}
JApplet [] g = new JApplet[]{new GraphicsOnly(), new MatrixView(), new SplitterView(k[0],k[1])};
public void init() {

//1. Get a handle on the applet's content pane.

container = this.getContentPane();

// NOTE: to reduce the amount of code in this example, it uses
// panels with a NULL layout. This is NOT suitable for
// production code since it may not display correctly for
// a given look-and-feel.

JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );

// Create the tab pages

//createPage1(); createPage2(); createPage3();

// Create a tabbed pane

tabbedPane = new JTabbedPane();
//SplitterView applet = new SplitterView(k[0], k[1]/*new JPanel(),new JPanel()*/);
for(JApplet j : g) j.init();
tabbedPane.addTab( "Page 1", panel[0] );
tabbedPane.addTab( "Page 2", panel[1] );
tabbedPane.addTab( "Page 3", panel[2] );
tabbedPane.addTab("page 4", g[0]);
tabbedPane.addTab("page 5", g[1]);
tabbedPane.addTab("page 6", g[2]);
topPanel.add( tabbedPane, BorderLayout.CENTER );

}

public JPanel createPage1() {
JPanel panel1 = new JPanel();
panel1.setLayout( null );

JLabel label1 = new JLabel( "Username:" );
label1.setBounds( 10, 15, 150, 20 );
panel1.add( label1 );

JTextField field = new JTextField();
field.setBounds( 10, 35, 150, 20 );
panel1.add( field );

JLabel label2 = new JLabel( "Password:" );
label2.setBounds( 10, 60, 150, 20 );
panel1.add( label2 );

JPasswordField fieldPass = new JPasswordField();
fieldPass.setBounds( 10, 80, 150, 20 );
panel1.add( fieldPass );
return panel1;
}

public JPanel createPage2() {
JPanel panel2 = new JPanel();
panel2.setLayout( new BorderLayout() );

panel2.add( new JButton( "North" ), BorderLayout.NORTH );
panel2.add( new JButton( "South" ), BorderLayout.SOUTH );
panel2.add( new JButton( "East" ), BorderLayout.EAST );
panel2.add( new JButton( "West" ), BorderLayout.WEST );
panel2.add( new JButton( "Center" ), BorderLayout.CENTER );
return panel2;
}

public JPanel createPage3() {
JPanel panel3 = new JPanel();
panel3.setLayout( new GridLayout( 3, 2 ) );

panel3.add( new JLabel( "Field 1:" ) );
panel3.add( new TextArea() );
panel3.add( new JLabel( "Field 2:" ) );
panel3.add( new TextArea() );
panel3.add( new JLabel( "Field 3:" ) );
panel3.add( new TextArea() );
return panel3;
}
public static void main(String[] args) {
JApplet applet = new DemoTabbedPane();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(applet);
f.setSize(400,400);
f.setLocation(200,200);
// Since there is no AppletContext we have to
// call the required methods in the applet.
applet.init();
f.setVisible(true);
}

}
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
without the GraphicsOnly() and MatrixView() classes, we can't copy/paste/compile/run
the program and see the problem

can you post a sample working program, so we can see the problem
 
Siegfried Heintze
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the thread "Wanted: Java2D example of zooming and panning with scroll bars" in the forum "JavaRanch Big Moose Saloon � Java � Other Java APIs" and look for GraphicsOnly.java that Craig posted there. Copy GraphicsOnly.java to MatrixView.java and perform a s/GraphicsOnly/MatrixView/g internally.

Incidently, I have anothor question: I'm curious about that comment the original author made in the TabbedPane example I downloaded (and pasted above). Why is using the null layout manager a problem? I thougth that was a legal thing to do. And why are we using the null layout manager? I thought the default was the flow layout. And finally: where would I explicitly specify a different layout manager? Here is the comment from the source code:

// NOTE: to reduce the amount of code in this example, it uses
// panels with a NULL layout. This is NOT suitable for
// production code since it may not display correctly for
// a given look-and-feel.

If it would be helpful, I can setup a web page applet so you can see the problem yourself. But even if I did, you would probably want to download and run the source code anyway. Let me know if you want me to setup that web page.


thanks,
siegfried
 
Siegfried Heintze
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Woops, I forgot to mention to scroll up for Craig's enhancements to class splitter view.

I see now where the other author (of my JTabbedpane example) is explicitly using the null layout manager now. Maybe I'll experiment with using the FlowLayout manager in its place.


siegfried
 
Siegfried Heintze
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please click on the "Page 6" tab at this URL to see the problem. Click on "Page 4" and "Page 5" and see that when there is no splitterView, everything is fine.

Here is the URL:

http://209.97.230.250/applets/DemoTabbedPane.html

Thanks
Siegfried
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this for DemoTabbedPane.java

 
Siegfried Heintze
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks good from the command line with the applet inside a JFrame!

Thank you very much!

Hmmm... my browser resident applets still have the same problem. How do I flush the caches for IE and Mozilla and Firefox?

Thanks,
Siegfried
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
by flushing the caches, do you mean changes to your applet are not updated?

if so, close all open browsers, including the one you are using to view JavaRanch,
then run your html file.

but running it via html won't call main(), which is where the setDividerLocation() is

see what happens if you add this method to DemoTabbedPane.java



you could also try putting a start() method in SplitterView (instead of
in DemoTabbedPane()), then it would be just pane.setDividerLocation(0.5);
 
Siegfried Heintze
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Michael Dunn,

I added the little start function. This may have fixed it. I should have tested it in IE before adding the start function and then I would know for sure.

Anyway, it is working correctly in IE but not Mozilla. This suggests that mozilla is caching it instead of getting a fresh copy from the web site. There must be a way to delete this cache in Mozilla.

I used to remember how to delete the cache in IE: you go to some directory and there are special icons representing the activeX controls (swing applets are loaded by activeX controls, are they activeX controls themselves?) and you delete these pseudo files. Deleting these pseudo files (I believe) automatically removes them from the registry.

There must be a similar directory for mozilla even if mozilla does not use activex/com!

Thanks,
siegfried
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can try control panel/java plugin/cache/clear cache

but if all else fails, copying the .java files into another directory
and recompiling usually works
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic