Hallo
Ich habe geschafft, ein Bild in meinem JFrame zu öffnen mithilfe von JFileChooser.. Ich will es aber in einem bestimmten JPanl öffnen...
derzeit sieht so aus:
also kann ich in dem menü gehen öffnen ankliken und dasbild öffnet sich direkt auf dem jframe...
ich will aber dass wenn ich auf öffnen klicke sich Instanz der Klasse CreateFile erstellt und das Bild in editPanel öffnen und nur da
Ich habe geschafft, ein Bild in meinem JFrame zu öffnen mithilfe von JFileChooser.. Ich will es aber in einem bestimmten JPanl öffnen...
derzeit sieht so aus:
Java:
public class GUI extends JFrame implements ActionListener{
static GUI gui = new GUI();
BufferedImage mImage;
private Image img;
public GUI() {
initComponents();
setTitle("Layout Tool");
setSize(900,900);
setBackground(new Color(42, 38, 36));
// img = Toolkit.getDefaultToolkit().createImage("C:\\Images\\Background.jpg");
ImageIcon icon = new ImageIcon("C:\\Images\\logo.gif");
img=icon.getImage();
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
void initComponents() {
.............
menubar = new JMenuBar();
menuFile = new JMenu();
menuAds = new JMenu();
neu = new JMenuItem();
open = new JMenuItem();
............
//Menue Datei
menuFile.setText("Datei");
neu.setMnemonic(KeyEvent.VK_N);
neu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));
neu.setText("Neu");
neu.addActionListener(this);
menuFile.add(neu);
...........
menubar.add(menuFile);
................
}
public void actionPerformed(ActionEvent object) {
//Neu
if (object.getSource() == neu){
CreateFile n1 = new CreateFile();
setContentPane(n1);
revalidate();
repaint();
}
//Oeffnen
if (object.getSource() == open){
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileNameExtensionFilter("*.jpg;*.gif","jpg", "gif"));
int state = fc.showOpenDialog(GUI.this);
if ( state == JFileChooser.APPROVE_OPTION ){
File file = fc.getSelectedFile();
BufferedImage bi;
try {
bi = ImageIO.read(file);
image_label.setIcon(new ImageIcon(bi));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// catch IOException
}
}
also kann ich in dem menü gehen öffnen ankliken und dasbild öffnet sich direkt auf dem jframe...
ich will aber dass wenn ich auf öffnen klicke sich Instanz der Klasse CreateFile erstellt und das Bild in editPanel öffnen und nur da
Java:
public class CreateFile extends JPanel implements ActionListener
{
static CreateFile cf = new CreateFile();
public CreateFile()
{
initComponents();
}
public void initComponents()
{
.......
tabbedPane = new JTabbedPane();
editPanel = new EditPanel();
editPanel.setPreferredSize(new Dimension(1000,1000));
scrollPane=new JScrollPane(editPanel);
// editPanel. setAutoscrolls(true);
scrollPane.setPreferredSize(new Dimension(600,600));
websitePanel = new JPanel();
layoutPanel = new JPanel();
fixFormsPanel = new JPanel();
individualFormsPanel = new JPanel();
.................
editPanel.setBackground(lightGrayPanel);
// Border tb_edit = BorderFactory.createEtchedBorder(1, lightGrayPanel,darkGrayPanel);
// editPanel.setBorder(tb_edit);
GroupLayout editPanelLayout = new GroupLayout(editPanel);
editPanel.setLayout(editPanelLayout);
editPanelLayout.setHorizontalGroup(
editPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGap(2,2,2)
);
editPanelLayout.setVerticalGroup(
editPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGap(2,2,2)
);
scrollPane.setViewportView(editPanel);
tabbedPane.addTab("neu", scrollPane);
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
this.setBackground(darkGrayPanel);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(tabbedPane, GroupLayout.DEFAULT_SIZE,GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
.addComponent(websitePanel, GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
.addComponent(layoutPanel, GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
.addComponent(fixFormsPanel, GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
.addComponent(individualFormsPanel, GroupLayout.DEFAULT_SIZE,0, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(20 , 20, 20)
.addComponent(websitePanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(layoutPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(fixFormsPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(individualFormsPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addComponent(tabbedPane, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
}
......
}