Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did a similar thing with a jFrame, I got around it by adding 4 very thin buttons around the outside of my jFrame, and used the mousepressed and mousedragged listener from the buttons to control jFrame resizing, it worked out pretty smoothly.</p> <p>The mousePressed listener lets us get the starting location so I can calculate the distance that the frame is dragged/resized</p> <p>If you want to save on resources you should resize all child components when the mouse is released not when it is dragged</p> <p>Edit: Example of resizing the frame on the X axis.</p> <pre><code>public class NewJFrame extends javax.swing.JFrame { //demo locations int X1 = 0; int X2 = 0; public NewJFrame() { initComponents(); } @SuppressWarnings("unchecked") private void initComponents() { ResizeEast = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setUndecorated(true); ResizeEast.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent evt) { ResizeEastMousePressed(evt); } public void mouseReleased(java.awt.event.MouseEvent evt) { ResizeEastMouseReleased(evt); } }); ResizeEast.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() { public void mouseDragged(java.awt.event.MouseEvent evt) { ResizeEastMouseDragged(evt); } }); jButton1.setText("Close"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 320, Short.MAX_VALUE) .addComponent(ResizeEast, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jButton1) .addContainerGap(266, Short.MAX_VALUE)) .addComponent(ResizeEast, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE) ); pack(); } private void ResizeEastMousePressed(java.awt.event.MouseEvent evt) { //set mosuepressed location to X1 and Y1 X1 = evt.getX(); } private void ResizeEastMouseReleased(java.awt.event.MouseEvent evt) { //update the location and size of all child components } private void ResizeEastMouseDragged(java.awt.event.MouseEvent evt) { //resize jframe on the fly X2 = evt.getX(); //set minimum size to 100 wide if ((getWidth() - (X1 - X2)) &lt; 100) { X2 = X1; } //resize east side only this.setSize(getWidth() - (X1 - X2), getHeight()); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new NewJFrame().setVisible(true); } }); } // Variables private javax.swing.JButton ResizeEast; private javax.swing.JButton jButton1; } </code></pre> <p>For re-sizing from the corners create small corner buttons that resize X and Y like so: <code>YourFrame.setSize(getWidth() - (X1 - X2), getHeight() - (Y1 - Y2));</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload