Weder innerhalb des JApplets noch des JDialogs lässt sich bei mir der Viewport setzen
Wo liegt der Fehler :confused:
Bin wirklich über jede Hilfe danbkar!!
Java
// ScrollPaneApplet.java
import java.awt.*;
import javax.swing.*;
public class ScrollPaneApplet extends JApplet {
private JPanel jContentPane = null;
private JScrollPane jScrollPane = null;
private ScrollPanePanel jScrollPaneViewport = null;
public ScrollPaneApplet() { super(); }
public void init() {
this.setSize(600, 400);
this.setContentPane(getJContentPane());
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setSize(new Dimension(600, 400));
jContentPane.setPreferredSize(new Dimension(600, 400));
jContentPane.add(getJScrollPane(), null);
}
return jContentPane;
}
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setSize(new Dimension(400, 300));
jScrollPane.setPreferredSize(new Dimension(400, 300));
jScrollPane.setBounds(new Rectangle(33, 28, 400, 300));
jScrollPane.setLocation(new Point(33,28));
jScrollPane.setBorder(BorderFactory.createLineBorder(Color.red, 1));
jScrollPane.setViewportView(jScrollPaneViewport);
}
return jScrollPane;
}
}
Alles anzeigen
Java
// ScrollPaneDialog.java
import javax.swing.*;
import java.awt.*;
import javax.swing.BorderFactory;
import java.awt.Color;
public class ScrollPaneDialog extends JDialog {
private JPanel jContentPane = null;
private JScrollPane jScrollPane = null;
private ScrollPanePanel jScrollPaneViewport = null;
public ScrollPaneDialog() {
super();
initialize();
}
private void initialize() {
this.setSize(new java.awt.Dimension(600, 400));
this.setPreferredSize(new java.awt.Dimension(600, 400));
this.setContentPane(getJContentPane());
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setSize(new Dimension(600, 400));
jContentPane.setPreferredSize(new Dimension(600, 400));
jContentPane.add(getJScrollPane(), null);
}
return jContentPane;
}
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setSize(new Dimension(400, 300));
jScrollPane.setPreferredSize(new Dimension(400, 300));
jScrollPane.setLocation(new Point(30, 30));
jScrollPane.setBorder(BorderFactory.createLineBorder(Color.red, 1));
jScrollPane.setViewportView(jScrollPaneViewport);
}
return jScrollPane;
}
public static void main(String[] args) {
ScrollPaneDialog spd = new ScrollPaneDialog();
spd.setVisible(true);
}
}
Alles anzeigen
Java
// ScrollPanePanel.java
import javax.swing.*;
import java.awt.*;
public class ScrollPanePanel extends JPanel {
private JButton jButton = null;
private JButton jButton1 = null;
public ScrollPanePanel() {
super();
initialize();
}
private void initialize() {
this.setLayout(null);
this.setSize(new Dimension(1200, 800));
this.setPreferredSize(new Dimension(1200, 800));
this.add(getJButton(), null);
this.add(getJButton1(), null);
}
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(52, 115, 83, 53));
jButton.setText("1");
}
return jButton;
}
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(894, 605, 106, 46));
jButton1.setText("2");
}
return jButton1;
}
}
Alles anzeigen