View Full Version : سوال: حذف حاشیه های JFrame
سایانا
دوشنبه 04 آبان 1394, 16:29 عصر
برای اینکه حاشیه ها رو از پنجره اصلی یا همون jframe حذف کنیم باید چکار کنیم؟
در صورت حذف حاشیه ها طبیعتا دکمه های close , minimize , restore Down رو نخواهیم داشت. بنابراین برای داشتن اونها در پنجره در حالی که حاشیه نداریم باید چه کنیم؟
دقیق تر بخوام بگم پنجره ای میخوام که مثل پنجره word2013 باشه و نمیدونم چطور باید اون رو طراحی کنم.:متفکر: :لبخند:
راه حل میخوام.
سایانا
پنج شنبه 07 آبان 1394, 16:52 عصر
تابع setUndecorated(true) باعث میشه حاشیه های jframe از بین بره. اگه کسی خواست میتونه این لینک هم ببینه.
http://stackoverflow.com/questions/2011601/jframe-without-frame-border-maximum-button-minimum-button-and-frame-icon
سایانا
پنج شنبه 07 آبان 1394, 17:33 عصر
این نمونه کد هم یک دکمه close برای یک پنجره ی بی حاشیه میسازه.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package testframeclose;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
/**
*
* @author Sadeghi
*/
public class TestFrameclose {
public static void main(String[] args) {
new TestFrameclose();
}
public TestFrameclose() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
}
TitlePane titlePane = new TitlePane();
JFrame frame = new JFrame("Testing");
frame.setUndecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setLayout(new BorderLayout());
((JComponent)frame.getContentPane()).setBorder(new LineBorder(Color.BLACK));
frame.add(titlePane, BorderLayout.NORTH);
frame.add(new JLabel("This is your content", JLabel.CENTER));
frame.setSize(600, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
public class TitlePane extends JPanel {
public TitlePane() {
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1;
gbc.anchor = GridBagConstraints.EAST;
add(new CloseControl(), gbc);
}
}
public class CloseControl extends JButton {
public CloseControl() {
setBorderPainted(false);
setContentAreaFilled(false);
setFocusPainted(false);
setOpaque(false);
setBorder(new EmptyBorder(0, 0, 8, 12));
try {
setRolloverIcon(new ImageIcon(ImageIO.read(new File("F://aks//1.jpg"))));
setRolloverEnabled(true);
setIcon(new ImageIcon(ImageIO.read(new File("F://aks//close.png"))));
} catch (IOException ex) {
Logger.getLogger(TestFrameclose.class.getName()).l og(Level.SEVERE, null, ex);
}
addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SwingUtilities.getWindowAncestor(CloseControl.this ).dispose();
}
});
}
}
}
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.