0

ok so heres my question..
i need to create a software that fits for 1280x800 resoultion and our programming team has 1366x768 screens. So we decided it wud be cool to develop the UI like the Windows 8 start screen or the Nokia Lumia Home Screen. Thus we want to put a panel inside a scrollpane.

I found this piece of code from a site it completes our requirement. But problem is that we can not implement this in Netbeans. As the question says I need sum visual help on how to fix this in Netbeans. We are capable of hard coding it but I dont think it wud be preferred by the team.

package test;

import java.awt.*;

import javax.swing.*;

public class NewClass extends JFrame {

public NewClass() throws HeadlessException {
    final JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createLineBorder(Color.red));
    panel.setPreferredSize(new Dimension(800, 600));
    panel.setBackground(Color.black);
    final JScrollPane scroll = new JScrollPane(panel);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new BorderLayout());
    add(scroll, BorderLayout.CENTER);
    setSize(300, 300);
    setVisible(true);
 }
public static void main(final String[] args) throws Exception {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            new NewClass().setVisible(true);
        }
    });
}
}

here's a screenshot of the image

enter image description here

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • I have deleted inflammatory comments. Please don't go there. – Hovercraft Full Of Eels Aug 27 '14 at 19:21
  • 2
    With NetBeans or with hard coding, you can tell the GUI to be maximized, to fill the screen (if that is your desire). You can set the layout of any component, including the JFrame's contentPane. Why not make it a BorderLayout, add your JScrollPane to it, BorderLayout.CENTER, and then add your variable sized GUI JPanel to the JScrollPane's viewport? – Hovercraft Full Of Eels Aug 27 '14 at 19:23
  • @HovercraftFullOfEels thanx man i thought like that too.. would like some visual help.. bit lost here – JWanniarachchi Aug 27 '14 at 19:24
  • 1
    I don't use NetBeans and so I can't give chapter and verse how to do things in NetBeans, but I'm guessing that the JFrame (or maybe its JRootPane) will have a property that allows maximization to the screen, and I know for certain that you can select the layout that it uses. – Hovercraft Full Of Eels Aug 27 '14 at 19:27
  • @HovercraftFullOfEels yes we can the problem is like this.. we can make a jframe.. we can set the borderlayout and... should i put the panel first or the scrollpane.. anyway if i add panel then scrollpane and wen i set viewport it says adding parent thingy.. i guess that means you cant set viewport wen scrollpane is under panel.. right? so what should i do – JWanniarachchi Aug 27 '14 at 19:31
  • 1
    The component to be displayed by the JScrollPane is added **to** the JScrollPane, either added in its constructor or into its viewport's view. The JScrollPane is then added to the main GUI BorderLayout.CENTER. – Hovercraft Full Of Eels Aug 27 '14 at 19:34
  • @HovercraftFullOfEels heyyy that worked.. thanx man sorry if i was a bother i got the basic set up like in the image.. thanx dude i owe u.. – JWanniarachchi Aug 27 '14 at 19:46
  • Glad you've got things working, and no bother (other than that one line that I deleted). – Hovercraft Full Of Eels Aug 27 '14 at 19:47
  • Note that you may be able to fit your entire GUI without a JScrollPane with a smart nesting of JPanels and use of layout managers. Again, this can all be done via the NetBeans builder, and the users would likely appreciate not having to scroll to see the entire GUI. – Hovercraft Full Of Eels Aug 27 '14 at 19:48
  • Gak, you put the offending text back in. Re-removed! – Hovercraft Full Of Eels Aug 27 '14 at 19:58
  • 1
    Consider using the approach suggested [here](http://stackoverflow.com/a/2561540/230513). – trashgod Aug 27 '14 at 20:20

0 Answers0