Results 1 to 3 of 3
  1. #1
    gustio is offline Member
    Join Date
    Jun 2008
    Posts
    14
    Rep Power
    0

    Default [SOLVED] jScrool in JInternalFrame

    I use jScrool with panel as container for showing a lot of input data. I was tried with JDialog and run well but I can't adjusted screen resolution with this. So, i try with JInternalFrame, but jScrool can't scrool to view another display. I use Netbeans IDE. How I solve this?

    Salam,
    bagianto

  2. #2
    Niveditha's Avatar
    Niveditha is offline Senior Member
    Join Date
    May 2008
    Posts
    307
    Rep Power
    7

    Default

    This code works..

    Java Code:
    Panel myPanel = new Panel(); 
    		myPanel.setLayout(null);
    		myPanel.setMaximumSize(new Dimension(900, 3950));   		
                              myPanel.setPreferredSize(new Dimension(900, 600)); 
    		scrollPane = new JScrollPane(myPanel,
    				ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
    				ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    Is this you want or something else?
    Please be clear on it and if possible put the part of code you are stuck up with and any errors you face.
    To finish sooner, take your own time....
    Nivedithaaaa

  3. #3
    gustio is offline Member
    Join Date
    Jun 2008
    Posts
    14
    Rep Power
    0

    Default

    Thank you for your advice. I was tried with Netbeans 6.1 and that’s work. In Netbeans, jScrool can change horizontal resizability but not vertical. It is my code (I modified from template netbeans):
    If I make mistake or can make this code more efficient, give me more advice.

    /*
    * MainFrame.java
    *
    * Created on 22 Juli 2008, 14:01
    */

    package mainframe;

    import org.jdesktop.application.Action;

    public class MainFrame extends javax.swing.JFrame {
    /** Creates new form MainFrame */
    public MainFrame() {
    initComponents();

    // make form with computer resolution screen
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize ();
    setBounds(0, 0, (screenSize.width), (screenSize.height)-30);

    getRootPane().setDefaultButton(showButton);
    }

    @Action
    public void showJInternalFrame() {
    mainPanel.removeAll();
    repaint();
    ReferenceFrame reference = new ReferenceFrame();
    reference.setSize(mainPanel.getSize().width, mainPanel.getSize().height);
    reference.show();
    mainPanel.add(reference);
    }

    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

    showButton = new javax.swing.JButton();
    mainPanel = new javax.swing.JPanel();

    setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
    setName("Form"); // NOI18N

    javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(m ainframe.MainFrameApp.class).getContext().getActio nMap(MainFrame.class, this);
    showButton.setAction(actionMap.get("showJInternalF rame")); // NOI18N
    org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(m ainframe.MainFrameApp.class).getContext().getResou rceMap(MainFrame.class);
    showButton.setText(resourceMap.getString("showButt on.text")); // NOI18N
    showButton.setName("showButton"); // NOI18N
    showButton.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent evt) {
    showButtonMouseClicked(evt);
    }
    });

    mainPanel.setName("mainPanel"); // NOI18N

    javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
    mainPanel.setLayout(mainPanelLayout);
    mainPanelLayout.setHorizontalGroup(
    mainPanelLayout.createParallelGroup(javax.swing.Gr oupLayout.Alignment.LEADING)
    .addGap(0, 786, Short.MAX_VALUE)
    );
    mainPanelLayout.setVerticalGroup(
    mainPanelLayout.createParallelGroup(javax.swing.Gr oupLayout.Alignment.LEADING)
    .addGap(0, 360, Short.MAX_VALUE)
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addComponent(showButton)
    .addContainerGap(653, Short.MAX_VALUE))
    .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addComponent(showButton)
    .addGap(18, 18, 18)
    .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addGap(31, 31, 31))
    );

    pack();
    }// </editor-fold>

    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new MainFrame().setVisible(true);
    }
    });
    }

    private void showButtonMouseClicked(java.awt.event.MouseEvent evt) {
    // TODO add your handling code here:
    }

    // Variables declaration - do not modify
    private javax.swing.JPanel mainPanel;
    private javax.swing.JButton showButton;
    // End of variables declaration

    }


    /*
    * ReferenceFrame.java
    *
    * Created on 22 Juli 2008, 13:57
    */

    package mainframe;

    public class ReferenceFrame extends javax.swing.JInternalFrame {

    /** Creates new form ReferenceFrame */
    public ReferenceFrame() {
    initComponents();
    }

    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

    jScrollPane1 = new javax.swing.JScrollPane();
    jPanel1 = new javax.swing.JPanel();

    setClosable(true);
    setName("Form"); // NOI18N

    jScrollPane1.setName("jScrollPane1"); // NOI18N

    jPanel1.setName("jPanel1"); // NOI18N

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
    .addGap(0, 797, Short.MAX_VALUE)
    );
    jPanel1Layout.setVerticalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
    .addGap(0, 339, Short.MAX_VALUE)
    );

    jScrollPane1.setViewportView(jPanel1);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(21, 21, 21)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 807, Short.MAX_VALUE)
    .addGap(21, 21, 21))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(39, 39, 39)
    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(75, Short.MAX_VALUE))
    );

    pack();
    }// </editor-fold>


    // Variables declaration - do not modify
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration

    }


    /*
    * MainFrameApp.java
    */

    package mainframe;

    import org.jdesktop.application.Application;
    import org.jdesktop.application.SingleFrameApplication;

    /**
    * The main class of the application.
    */
    public class MainFrameApp extends SingleFrameApplication {

    /**
    * At startup create and show the main frame of the application.
    */
    @Override protected void startup() {
    //show(new MainFrame(this));
    }

    /**
    * This method is to initialize the specified window by injecting resources.
    * Windows shown in our application come fully initialized from the GUI
    * builder, so this additional configuration is not needed.
    */
    @Override protected void configureWindow(java.awt.Window root) {
    }


    /**
    * A convenient static getter for the application instance.
    * @return the instance of MainFrameApp
    */
    public static MainFrameApp getApplication() {
    return Application.getInstance(MainFrameApp.class);
    }

    }

    Salam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •