How to right align the text in a ComboBox in Java

Nancy Den
Updated on 30-Jul-2019 22:30:26

274 Views

To right align the text in a JComboBox, use the following:ComponentOrientation.RIGHT_TO_LEFTThe following is an example to right align the text in a ComboBox:Exampleimport java.awt.Component; import java.awt.ComponentOrientation; import javax.swing.DefaultListCellRenderer; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JList; public class SwingDemo extends JFrame {    public SwingDemo() {       JComboBox combo = new JComboBox();       combo.setRenderer(new MyListCellRenderer());       combo.addItem("One");       combo.addItem("Two");       combo.addItem("Three");       combo.addItem("Four");       combo.addItem("Five");       getContentPane().add(combo, "North");       setSize(600, 400);       setDefaultCloseOperation(EXIT_ON_CLOSE);    }    public static void main(String[] args) { ... Read More

How to set tooltip text for JCheckBox in Java?

Nancy Den
Updated on 30-Jul-2019 22:30:26

222 Views

For JCheckBox, use the following to set tooltip text:checkBox1.setToolTipText("Sports Football"); checkBox2.setToolTipText("Sports Tennis");Tooltip text is visible whenever you will place cursor on that particular text.The following is an example. Here, we have set the tooltip text for both the sports:Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class SwingDemo {    private JFrame mainFrame;    private JLabel headerLabel;    private JLabel statusLabel;    private JPanel controlPanel;    public SwingDemo(){       prepareGUI();    }    public static void main(String[] args){       SwingDemo swingControlDemo = new SwingDemo();       swingControlDemo.showCheckBoxDemo();    }    private void prepareGUI(){       ... Read More

Java DatabaseMetaData supportsResultSetHoldability() method with example

Arushi
Updated on 30-Jul-2019 22:30:26

24 Views

ResultSet holdability determines whether the ResultSet objects (cursors) should be closed or held open when a transaction (that contains the said cursor/ ResultSet object) is committed using the commit() method of the Connection interface.The ResultSet interface provides two values to specify the holdability of a ResultSet namely −CLOSE_CURSORS_AT_COMMIT: If the holdability of the ResultSet object is set to this value. Whenever you commit/save a transaction using the commit() method of the Connection interface, the ResultSet objects created in the current transaction (that are already opened) will be closed.HOLD_CURSORS_OVER_COMMIT: If the holdability of the ResultSet object is set to this value. ... Read More

What is the precision of floating point in C++?

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

778 Views

In C++, the size of the floating point number is either 4-byte or 8-bytes. So it can store up to few decimal places. For example, the 1/3 = 0.333333…… Up to infinity. If we store it inside floating type variable, then it will store some significant digits. The default value is 6. So normally floating point numbers in C++ can display up to 6 decimal places.We can change the size of the precision using setprecision. This is present inside the iomanip header file. Let us see one example to get the idea.Example Code#include #include using namespace std; int ... Read More

How to create a Vertical menu bar in Java?

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

692 Views

Let us create a MenuBar −JMenuBar menuBar = new JMenuBar();Now, set its layout to create a Vertical Menu Bar with GridLayout −menuBar.setLayout(new GridLayout(0, 1));The following is an example to create a Vertical menu bar in Java −Examplepackage my; import java.awt.GridLayout; import java.awt.event.KeyEvent; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; public class SwingDemo {    public static void main(final String args[]) {       JFrame frame = new JFrame("MenuBar Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       JMenuBar menuBar = new JMenuBar();       menuBar.setLayout(new GridLayout(0, 1));       JMenu fileMenu = new JMenu("File");       ... Read More

How to get the date between TODAY and TODAY-7”?

George John
Updated on 30-Jul-2019 22:30:26

6K+ Views

To get the date between dates, you need to use. Here, we are getting the dates between today and today-7 days −select *from yourTableName where DATE(yourColumnName) > (NOW() - INTERVAL 7 DAY);Note : Let’s say the current date is '2019-06-02’ Let us first create a table.mysql> create table DemoTable    (    LoginDate date    ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2018-03-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2019-05-22'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('2019-05-27'); ... Read More

Read integers from a text file with C++ ifstream

Smita Kapse
Updated on 30-Jul-2019 22:30:26

5K+ Views

Here is an example of Read integers from a text file with C++ ifstream.Example#include #include using namespace std; int main() {    //initialie the array size    int arr[30];    ifstream is("a.txt");    int cnt= 0;    int x;    // check that array is not already full    while (cnt < arr[30] && is >> x)    // and read integer from file    arr[cnt++] = x;    // print the integers stored in the array    cout

Update table with duplicate ids in MySQL

Kumar Varma
Updated on 30-Jul-2019 22:30:26

465 Views

Following is the syntax −update yourTableName set yourColumnName1= yourValue where yourColumnName2=yourValue order by yourColumnName2 DESC LIMIT 1;Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> Name varchar(100)    -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1, 'John'); Query OK, 1 row affected (0.41 sec) mysql> insert into DemoTable values(2, 'Chris'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(2, 'Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into ... Read More

HTML DOM Input Month readOnly Property

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

65 Views

The HTML DOM input month readOnly property returns and modify whether the input month field is read-only or not in an HTML document.SyntaxFollowing is the syntax −1. Returning readOnlyobject.readOnly2. Modifying readOnlyobject.readOnly = true | falseExample Live DemoLet us see an example of HTML DOM input month readOnly property−    html{       height:100%;    }    body{       text-align:center;       color:#fff;       background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%)       center/cover no-repeat;       height:100%;    }    p{       font-weight:700;       font-size:1.1rem;    } ... Read More

Add minimum number to an array so that the sum becomes even in C++?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

68 Views

Suppose there is an array with some numbers. We have to tell minimum how many numbers will be added with it to make the sum of the elements even. The number must be greater than 0. So if the sum of the elements is odd, we will add 1, but if the sum is already even, then we will add 2 with it to make it even.AlgorithmaddMinNumber(arr)begin    s := 0    for each element e from arr, do       s := e + s    done    if s is even, then return 2, otherwise 1 endExample Live ... Read More

Advertisements